-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathwebpack.config.js
executable file
·123 lines (121 loc) · 3.47 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
const webpack = require('webpack'),
path = require('path'),
glob = require('glob'),
PurgecssPlugin = require('purgecss-webpack-plugin'),
MiniCssExtractPlugin = require('mini-css-extract-plugin'),
OptimizeCSSAssetsPlugin = require("optimize-css-assets-webpack-plugin"),
RemovePlugin = require('remove-files-webpack-plugin'),
UglifyJsPlugin = require('uglifyjs-webpack-plugin'),
ZipPlugin = require('zip-webpack-plugin'),
CopyWebpackPlugin = require('copy-webpack-plugin'),
ConcatPlugin = require('webpack-concat-plugin'),
isProd = (process.env.NODE_ENV == 'production');
function getOutputPath() {
return isProd ? './dist/' : './dev/';
}
module.exports = {
entry: {
'options.js': './src/main/options/main.js',
'options-styles': './src/main/options/styles/options-styles.scss'
},
output: {
filename: function(chunkData) {
return chunkData.chunk.name.indexOf('.js') !== -1 ? './[name]' : './[name].tmp';
},
path: path.resolve(__dirname, getOutputPath()),
publicPath: '/',
},
devtool: isProd ? false : 'source-map',
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env'],
plugins: ['add-filehash']
},
},
{
test: /\.scss$/,
use: [
MiniCssExtractPlugin.loader,
{ loader: 'css-loader' },
{
loader: 'sass-loader',
options: { sourceMap: !isProd }
}
]
},
{
test: /\.(png|ico)$/,
loader: ['file-loader?publicPath=./&name=[name].[ext]', 'image-webpack-loader']
}
]
},
plugins: [
new MiniCssExtractPlugin({
filename: "[name].css",
}),
new PurgecssPlugin({
paths: glob.sync(`src/main/options/*.html`),
}),
new webpack.DefinePlugin({
'process.env': {
'NODE_ENV': JSON.stringify(isProd ? 'production' : 'development'),
}
}),
new CopyWebpackPlugin([
{ from: './assets/fox-48px.png', to: 'fox-48px.png' },
{ from: './assets/fox-96px.png', to: 'fox-96px.png' },
{ from: './src/main/background/.tmp/service.wasm', to: 'service.wasm' },
{ from: './src/main/manifest.json', to: 'manifest.json' },
{ from: './src/main/options/index.html', to: 'options.html' },
{ from: './LICENSE', to: './LICENSE.txt' },
], {}),
new RemovePlugin({
before: {
root: __dirname,
include: [getOutputPath()]
},
after: {
root: __dirname,
test: [
{
folder: getOutputPath(),
method: (filePath) => {
return isProd ? new RegExp(/\.(?!(zip)$)([^.]+$)/, 'm').test(filePath) : new RegExp(/\.tmp$/, 'm').test(filePath);
}
}
]
}
}),
new ConcatPlugin({
uglify: isProd,
sourceMap: !isProd,
name: 'background',
fileName: '[name].js',
filesToConcat: ['./src/main/background/.tmp/service.js', './src/main/background/js/main.js'],
attributes: {
async: false
}
}),
new ZipPlugin({
filename: 'firefox-tab-suspender.zip',
exclude: [/\.tmp$/]
})
],
optimization: {
minimizer: isProd ? [
new UglifyJsPlugin(),
new OptimizeCSSAssetsPlugin({})
] : [],
},
node: {
fs: 'empty'
},
resolve: {
extensions: ['.js', '.json', '.html', '.wasm', '.css', 'scss']
}
};