-
Notifications
You must be signed in to change notification settings - Fork 6
/
webpack.config.babel.js
103 lines (98 loc) · 2.96 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
const path = require('path');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const TerserPlugin = require('terser-webpack-plugin');
const WriteJsonPlugin = require('write-json-webpack-plugin');
const webpack = require('webpack');
const config = require('./src/common/config');
const manifest = require('./src/manifest');
const packageJson = require('./package.json');
const sassLoader = {
loader: 'sass-loader',
options: {
additionalData: `
$namespace: ${config.namespace};
`,
},
};
const createConfig = (browser) => ({
mode: process.env.NODE_ENV === 'production' ? 'production' : 'development',
devtool: process.env.NODE_ENV === 'production' ? false : 'source-map',
entry: {
'content/content_medium': './src/content/content_medium.js',
'content/content_medium_iframe': './src/content/content_medium_iframe.js',
'content/content_substack': './src/content/content_substack.js',
'background/background': './src/background/background.js',
'app/App': './src/app/App.js',
},
output: {
path: path.resolve(__dirname, 'dist') + '/' + browser,
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: ['babel-loader'],
},
{
test: /\.scss$/,
use: [
{
loader: MiniCssExtractPlugin.loader, // creates style nodes from JS strings
},
{
loader: 'css-loader', // translates CSS into CommonJS
},
sassLoader,
],
},
],
},
plugins: [
new webpack.DefinePlugin({
'process.env.BROWSER': JSON.stringify(browser),
}),
new CleanWebpackPlugin({
cleanStaleWebpackAssets: false, // prevent cleaning of copied files (https://github.com/webpack-contrib/copy-webpack-plugin/issues/385#issuecomment-508914721)
cleanOnceBeforeBuildPatterns: [
path.resolve(__dirname, 'dist') + '/' + browser,
// exclude
`!.gitkeep`,
]
}),
new WriteJsonPlugin({
object: manifest(browser, packageJson.version),
filename: 'manifest.json',
pretty: true,
}),
new CopyWebpackPlugin({
patterns: [
{ from: 'src/assets', to: 'assets' },
{ from: 'src/background/background.html', to: 'background' },
{ from: 'src/app/index.html', to: 'app' },
{ from: 'src/app/assets', to: 'app/assets' },
],
}),
new MiniCssExtractPlugin({
filename: '[name].css',
chunkFilename: '[id].css',
}),
],
optimization: {
minimizer: [new TerserPlugin({
terserOptions: {
//minimize: true,
compress: {
evaluate: false,
inline: 1, // https://github.com/mishoo/UglifyJS2/issues/2842
},
output: {
ascii_only: true,
},
},
})],
},
});
module.exports = ['chrome', 'firefox'].map(createConfig);