forked from codysherman/Scroll-to-Top-Button-Extension
-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathwebpack.config.js
151 lines (144 loc) · 3.65 KB
/
webpack.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
const path = require( 'path' );
const { List, Map } = require( 'immutable' );
const CopyWebpackPlugin = require( 'copy-webpack-plugin' );
const { CleanWebpackPlugin } = require( 'clean-webpack-plugin' );
const WebpackCleanPlugin = require( 'webpack-clean' );
const MiniCssExtractPlugin = require( 'mini-css-extract-plugin' );
const DIST_FOLDER_PATH = path.resolve( __dirname, 'dist' );
const modeDevelopment = process.env.NODE_ENV === 'development';
const defaultConfig = Map( {
entry: {
'manifest': './src/manifest.json',
'background': './src/background/index.js',
'content-scripts': './src/content-scripts/index.js',
'options': './src/options/index.js',
'shared/elements/scroll-to-top-button': './src/shared/elements/scroll-to-top-button.css',
'shared/legacy/background': './src/background/legacy.js',
'shared/legacy/context-menus': './src/shared/context-menus/legacy.js',
'shared/legacy/i18n': './src/shared/i18n/legacy.js',
},
output: Map( {
filename: '[name].js',
chunkFilename: '[name].js',
path: DIST_FOLDER_PATH,
} ),
module: {
rules: [
{
test: /manifest.json$/,
exclude: /node_modules/,
loader: 'manifest-loader',
},
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
plugins: [
'@babel/plugin-proposal-class-properties',
'@babel/plugin-proposal-private-methods',
'@babel/plugin-transform-async-to-generator',
],
},
},
},
{
test: /\.css$/,
exclude: /node_modules/,
use: [
MiniCssExtractPlugin.loader,
'css-loader',
{
loader: 'postcss-loader',
options: {
ident: 'postcss',
},
},
],
},
],
},
plugins: List( [
new CleanWebpackPlugin( {
cleanOnceBeforeBuildPatterns: [
DIST_FOLDER_PATH,
]
} ),
new CopyWebpackPlugin( {
patterns: [
{
from: './static',
to: './',
},
{
from: './src/shared/buttons',
to: './shared/buttons',
},
{
from: './src/shared/images',
to: './shared/images',
},
]
} ),
new MiniCssExtractPlugin( {
filename: '[name].css',
} ),
] ),
resolve: {
alias: {
'@': path.resolve( __dirname, 'src' ),
Shared: path.resolve( __dirname, 'src', 'shared' ),
ContentScripts: path.resolve( __dirname, 'src', 'content-scripts' ),
Options: path.resolve( __dirname, 'src', 'options' ),
},
fallback: {
fs: false,
},
},
resolveLoader: {
modules: [
path.resolve( __dirname, 'src', 'loaders' ),
'node_modules',
],
},
devtool: modeDevelopment ?
'inline-source-map' :
false,
watch: modeDevelopment,
} );
const supportedBrowsers = [
'chromium',
'firefox',
// 'edge',
];
module.exports = supportedBrowsers.map( browserName => {
return defaultConfig
// Create a separate dist folder for each browser
.updateIn(
[
'output',
'path',
],
() => path.resolve( DIST_FOLDER_PATH, browserName ),
)
// Remove unused automatically-created JavaScript files post-build
.updateIn(
[
'plugins',
],
value => value.push(
new WebpackCleanPlugin(
[
'manifest.js',
'shared/elements/scroll-to-top-button.js',
],
{
basePath: path.resolve( DIST_FOLDER_PATH, browserName ),
},
),
),
)
.toJS()
;
} );