forked from honestbleeps/Reddit-Enhancement-Suite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.babel.js
163 lines (156 loc) · 4.08 KB
/
webpack.config.babel.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
152
153
154
155
156
157
158
159
160
161
162
163
/* @noflow */
/* eslint-disable import/no-nodejs-modules */
import path from 'path'; // eslint-disable-line import/no-extraneous-dependencies
import InertEntryPlugin from 'inert-entry-webpack-plugin';
import ZipPlugin from 'zip-webpack-plugin';
import sass from 'sass';
const browserConfig = {
chrome: {
target: 'chrome',
entry: 'chrome/manifest.json',
output: 'chrome',
},
chromebeta: {
target: 'chrome',
entry: 'chrome/beta/manifest.json',
output: 'chrome-beta',
},
firefox: {
target: 'firefox',
entry: 'firefox/manifest.json',
output: 'firefox',
noSourcemap: true,
},
opera: {
target: 'opera',
entry: 'chrome/manifest.json',
output: 'opera',
noSourcemap: true,
},
edge: {
target: 'edge',
entry: 'chrome/manifest.json',
output: 'edge',
},
};
export default (env = {}, argv = {}) => {
const isProduction = argv.mode === 'production';
const browsers = (
typeof env.browsers !== 'string' ? ['chrome'] :
env.browsers === 'all' ? Object.keys(browserConfig) :
env.browsers.split(',')
);
const configs = browsers.map(b => browserConfig[b]).map(conf => ({
entry: `extricate-loader!interpolate-loader!./${conf.entry}`,
output: {
path: path.join(__dirname, 'dist', conf.output),
filename: path.basename(conf.entry),
},
devtool: (() => {
if (!isProduction) return 'cheap-source-map';
if (!conf.noSourcemap) return 'source-map';
return false;
})(),
node: false,
performance: false,
module: {
rules: [{
test: /\.entry\.js$/,
use: [
{ loader: 'spawn-loader' },
],
}, {
test: /\.js$/,
exclude: path.join(__dirname, 'node_modules'),
use: [
{
loader: 'babel-loader',
options: {
plugins: [
'@babel/plugin-proposal-optional-chaining',
'@babel/plugin-proposal-export-namespace-from',
['@babel/plugin-proposal-class-properties', { loose: true }],
'@babel/plugin-transform-flow-strip-types',
'minify-dead-code-elimination',
['transform-define', {
'process.env.BUILD_TARGET': conf.target,
'process.env.NODE_ENV': argv.mode,
}],
],
comments: !isProduction,
babelrc: false,
},
},
],
}, {
test: /\.js$/,
include: path.join(__dirname, 'node_modules'),
exclude: path.join(__dirname, 'node_modules', 'dashjs', 'dist', 'dash.mediaplayer.min.js'),
use: [
{
loader: 'babel-loader',
options: {
plugins: [
'minify-dead-code-elimination',
['transform-define', {
'process.env.NODE_ENV': argv.mode,
}],
],
compact: true,
comments: false,
babelrc: false,
},
},
],
}, {
test: /\.scss$/,
use: [
{ loader: 'file-loader', options: { esModule: false, name: '[name].css' } },
{ loader: 'extricate-loader', options: { resolve: '\\.js$' } },
{ loader: 'css-loader', options: { esModule: false } },
{ loader: 'postcss-loader' },
{ loader: 'sass-loader', options: { implementation: sass } },
],
}, {
test: /\.html$/,
use: [
{ loader: 'file-loader', options: { esModule: false, name: '[name].[ext]' } },
{ loader: 'extricate-loader' },
{ loader: 'html-loader', options: { attrs: ['link:href', 'script:src'] } },
],
}, {
test: /\.(png|gif|svg)$/,
exclude: path.join(__dirname, 'lib', 'images'),
use: [
{ loader: 'file-loader', options: { esModule: false, name: '[name].[ext]' } },
],
}, {
test: /\.(png|gif|svg)$/,
include: path.join(__dirname, 'lib', 'images'),
use: [
{ loader: 'url-loader', options: { esModule: false } },
],
}, {
test: /\.woff$/,
use: [
{ loader: 'url-loader', options: { esModule: false } },
],
}],
},
optimization: {
minimize: false,
concatenateModules: true,
},
resolve: {
mainFields: ['module', 'main', 'browser'],
},
plugins: [
new InertEntryPlugin(),
(env.zip && !conf.noZip && new ZipPlugin({
path: path.join('..', 'zip'),
filename: conf.output,
})),
].filter(x => x),
}));
return (configs.length === 1 ? configs[0] : configs);
};