-
Notifications
You must be signed in to change notification settings - Fork 3
/
webpack.config.js
77 lines (74 loc) · 1.74 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
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const path = require('path');
const assetsDir = path.resolve('.', 'src', 'assets');
const Asset = ([str]) => path.resolve(assetsDir, str);
const configuration = {
mode: 'development',
entry: {
popup: path.resolve('.', 'src', 'popup.ts'),
background: path.resolve('.', 'src', 'background.ts'),
},
output: {
path: path.resolve(__dirname, 'dist'),
filename: '[name].js'
},
devtool: 'source-map',
module: {
rules: [
{
test: /\.tsx?$/,
exclude: /node_modules/,
use: {
loader: 'ts-loader',
options: {
transpileOnly: false,
configFile: 'tsconfig.json'
}
}
},
{
test: /\.scss$/,
use: [
'style-loader',
'css-loader',
'sass-loader'
]
}
]
},
plugins: [
new CleanWebpackPlugin(path.resolve('.', 'dist')),
new HtmlWebpackPlugin({
template: Asset`popup.html`,
filename: 'popup.html',
chunks: ["popup"]
}),
new CopyWebpackPlugin([{
from: Asset`manifest.json`,
transform: function (content, path) {
return Buffer.from(JSON.stringify({
...JSON.parse(content.toString())
}, null, 2))
}
},
{
from: Asset`*.png`,
flatten: true,
},
{
from: Asset`*.jpeg`,
flatten: true,
}]),
],
resolve: {
extensions: ['.js', '.ts']
},
};
const prodConfiguration = {
...configuration,
mode: 'production',
devtool: 'none'
}
module.exports = process.env.PRODUCTION ? prodConfiguration : configuration;