This repository has been archived by the owner on Apr 15, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwebpack.config.js
73 lines (69 loc) · 1.79 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
const webpack = require('webpack');
const path = require('path');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const CopyPlugin = require('copy-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
// `terser-webpack-plugin` can be used by default as webpack depends on it.
const TerserPlugin = require('terser-webpack-plugin');
const isProd = (process.env.NODE_ENV === 'production');
const config = {
mode: isProd ? 'production' : 'development',
entry: {
popup: './src/popup.js',
options: './src/options.js',
update: './src/update.js'
},
output: {
filename: 'scripts/[name].js',
chunkFilename: 'scripts/[name].js',
path: path.resolve(__dirname, 'dist')
},
optimization: {
minimizer: [new TerserPlugin(), new CssMinimizerPlugin()],
},
plugins: [
new CleanWebpackPlugin({
cleanOnceBeforeBuildPatterns: ['dist'],
}),
new CopyPlugin({
patterns: [
{ from: 'src/manifest.json' },
{ from: 'src/html', to: 'html' },
{ from: 'src/images', to: 'images' }
// { from: 'src/_locales', to: '_locales' }
]
}),
new MiniCssExtractPlugin({
filename: 'css/[name].css'
}),
],
module: {
rules: [
{
test: /\.scss$/,
use: [
{
loader: MiniCssExtractPlugin.loader,
},
'css-loader',
'sass-loader'
]
},
{
test: /\.html$/,
type: 'asset/resource'
},
{
test: /\.(png|svg|jpg|gif)$/,
type: 'asset/resource'
}
]
}
};
if (isProd) {
} else {
config.devtool = 'source-map';
config.plugins.push(new webpack.HotModuleReplacementPlugin());
}
module.exports = config;