forked from honestbleeps/Reddit-Enhancement-Suite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.babel.js
144 lines (137 loc) · 3.57 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
/* eslint-disable import/no-nodejs-modules */
import path from 'path';
import InertEntryPlugin from 'inert-entry-webpack-plugin';
import LodashModuleReplacementPlugin from 'lodash-webpack-plugin';
import ProgressBarPlugin from 'progress-bar-webpack-plugin';
import ZipPlugin from 'zip-webpack-plugin';
import webpack from 'webpack';
const browserConfig = {
chrome: {
target: 'chrome',
entry: 'chrome/manifest.json',
environment: 'chrome/environment',
output: 'chrome',
},
edge: {
target: 'edge',
entry: 'edge/appxmanifest.xml',
environment: 'edge/environment',
output: 'edgeextension/manifest/Extension',
outputFilename: '../appxmanifest.xml',
noZip: true,
},
firefox: {
target: 'firefox',
entry: 'firefox/package.json',
environment: 'firefox/environment',
output: 'firefox',
},
firefoxbeta: {
target: 'firefox',
entry: 'firefox/beta/package.json',
environment: 'firefox/environment',
output: 'firefox-beta',
},
};
export default (env = {}) => {
const browsers = (
typeof env.browsers !== 'string' ? ['chrome'] :
env.browsers === 'all' ? Object.keys(browserConfig) :
env.browsers.split(',')
);
const isProduction = process.env.NODE_ENV !== 'development';
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: conf.outputFilename || path.basename(conf.entry),
},
devtool: isProduction ? 'source-map' : 'cheap-source-map',
bail: isProduction,
performance: false,
resolve: {
alias: {
browserEnvironment$: path.join(__dirname, conf.environment),
},
},
module: {
rules: [{
test: /\.entry\.js$/,
use: [
{ loader: 'spawn-loader', options: { name: '[name].js' } },
],
}, {
test: /\.js$/,
exclude: path.join(__dirname, 'node_modules'),
use: [
{ loader: 'babel-loader' },
],
}, {
test: /\.js$/,
include: path.join(__dirname, 'node_modules'),
use: [
{
loader: 'babel-loader',
options: {
plugins: ['transform-dead-code-elimination', 'transform-node-env-inline'],
compact: true,
babelrc: false,
},
},
],
}, {
test: /\.mustache$/,
use: [
{ loader: 'mustache-loader' },
],
}, {
test: /\.scss$/,
use: [
{ loader: 'file-loader', options: { name: '[name].css' } },
{ loader: 'extricate-loader', options: { resolve: '\\.js$' } },
{ loader: 'css-loader' },
{ loader: 'postcss-loader' },
{ loader: 'sass-loader' },
],
}, {
test: /\.html$/,
use: [
{ loader: 'file-loader', options: { name: '[name].[ext]' } },
{ loader: 'extricate-loader' },
{ loader: 'html-loader', options: { attrs: ['link:href', 'script:src'] } },
],
}, {
test: /\.(png|gif)$/,
exclude: path.join(__dirname, 'lib', 'images'),
use: [
{ loader: 'file-loader', options: { name: '[name].[ext]' } },
],
}, {
test: /\.(png|gif)$/,
include: path.join(__dirname, 'lib', 'images'),
use: [
{ loader: 'url-loader' },
],
}],
noParse: [
// to use `require` in Firefox
/nativeRequire\.js$/,
],
},
plugins: [
new ProgressBarPlugin(),
new webpack.DefinePlugin({
'process.env': {
BUILD_TARGET: JSON.stringify(conf.target),
},
}),
new InertEntryPlugin(),
new LodashModuleReplacementPlugin(),
(env.zip && !conf.noZip && new ZipPlugin({
path: path.join('..', 'zip'),
filename: conf.output,
})),
].filter(x => x),
}));
return (configs.length === 1 ? configs[0] : configs);
};