-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathwebpack.config.js
77 lines (74 loc) · 2.04 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
'use strict';
const { includes } = require('lodash');
const path = require('path');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const TerserPlugin = require('terser-webpack-plugin');
const CopyPlugin = require('copy-webpack-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const isDev = !includes(process.argv, '-p');
const shouldWatch = includes(process.argv, '-w');
module.exports = {
mode: isDev ? 'development' : 'production',
watch: shouldWatch,
devtool: 'inline-source-map',
entry: {
background: './app/scripts/background.ts',
contentscript: './app/scripts/contentscript.ts',
devtools: './app/scripts/devtools.ts',
crisp: './app/scripts/crisp.tsx'
},
output: {
filename: 'scripts/[name].js',
path: path.resolve(__dirname, 'dist/')
},
module: {
rules: [
{
test: /\.(svg|png|jpe?g|gif)$/i,
loader: 'file-loader',
options: {
// don't add contenthash to names for production
// as it is a browser extension
name: '[name].[ext]',
outputPath: 'images',
publicPath: '../images'
},
},
{
test: /\.(ts|tsx)$/,
loader: 'ts-loader',
exclude: /node_modules/
},
{
test: /\.(css|less)$/i,
use: [MiniCssExtractPlugin.loader, 'css-loader', 'less-loader']
},
],
},
resolve: {
extensions: ['.ts', '.tsx', '.js'],
},
plugins: [
new CleanWebpackPlugin(),
new CopyPlugin({
patterns: [
{ from: 'app/manifest.json', to: 'manifest.json'},
{ from: 'app/images', to: 'images' },
{ from: 'app/libs', to: 'libs' }, // TODO import all libs' stylesheets and scripts from node_modules
{ from: 'app/pages', to: 'pages' }
],
}),
new MiniCssExtractPlugin({ filename: 'styles/[name].css' }),
],
optimization: {
minimizer: [
new TerserPlugin({
parallel: true,
terserOptions: {
keep_fnames: true,
mangle: false
}
}),
],
},
};