-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathwebpack.config.js
62 lines (60 loc) · 1.88 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
const path = require('path');
const CopyPlugin = require('copy-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const { VueLoaderPlugin } = require('vue-loader');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const version = require('./package.json').version;
module.exports = (env, argv) => {
const browser = env.browser || 'chrome';
return {
entry: {
popup: './src/popup/popup.js',
options: './src/options/options.js',
background: './src/background.js',
},
output: {
path: path.resolve(__dirname, 'dist', browser),
},
plugins: [
new CleanWebpackPlugin(), // Clean dist folder
new VueLoaderPlugin(), // Handle Vue files
new CopyPlugin({
patterns: [
{ context: 'assets', from: '**/*.{png,html}', to: '.' }, // Copy assets
{
context: 'assets',
from: `manifest.${browser}.json`,
to: 'manifest.json',
transform: (c) => c.toString().replace('%version%', version),
},
],
}),
new MiniCssExtractPlugin(), // Extract CSS to separate file
],
module: {
rules: [
// SASS/SCSS files
{
test: /\.s[ac]ss$/i,
use: [
MiniCssExtractPlugin.loader,
'css-loader',
{ loader: 'sass-loader', options: { implementation: require('sass') } },
],
},
// Vue files
{ test: /\.vue$/, loader: 'vue-loader' },
// Handle special comments: /* rm-<browser> */
{
test: /\.js$/,
loader: 'string-replace-loader',
options: {
search: new RegExp(`^.+\\* rm-${browser} \\*.+$`, 'gm'),
replace: '',
},
},
],
},
devtool: argv.mode === 'development' ? 'inline-source-map' : false, // Prevents chrome errors in dev mode
};
};