-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathwebpack.config.js
102 lines (98 loc) · 2.52 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
const path = require('path');
const json5 = require('json5');
const CleanTerminalPlugin = require('clean-terminal-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const WebpackShellPluginNext = require('webpack-shell-plugin-next');
module.exports = (env, args) => {
// NOTE: When adding an entry, add the corresponding source map file to
// web_accessible_resources in //templates/manifest.gjson.
let entry = {
background: './src/background.ts',
options: './src/options/options.ts',
};
let outputPath = path.join(__dirname, 'dist', env.browser_target);
let preprocessorLoader = {
loader: 'webpack-preprocessor-loader',
options: {
params: {
browser_target: env.browser_target,
production: args.mode == 'production',
canary: !!env.canary,
},
},
};
return {
entry,
output: {
filename: '[name].bundle.js',
path: outputPath,
clean: true,
},
plugins: [
new WebpackShellPluginNext({
onBuildEnd: {
scripts:
['genmanifest -template templates/manifest.gjson -dest ' +
path.join(outputPath, 'manifest.json') + ' ' +
env.browser_target]
}
}),
new CopyWebpackPlugin({
patterns: [
{
from: path.join(
__dirname, 'src/icons', env.canary ? 'canary' : 'regular'),
to: path.join(outputPath, 'icons'),
},
]
}),
new CopyWebpackPlugin({
patterns: [
{
from: path.join(__dirname, 'src/static'),
to: outputPath,
globOptions: {
ignore: ['**/OWNERS', '**.md'],
}
},
]
}),
new CleanTerminalPlugin(),
],
devtool: (args.mode == 'production' ? 'source-map' : 'inline-source-map'),
resolve: {
extensions: ['.ts', '.tsx', '...'],
},
module: {
rules: [
{
test: /\.json5$/i,
type: 'json',
parser: {
parse: json5.parse,
},
use: [
preprocessorLoader,
],
},
{
test: /\.js$/i,
use: [
{loader: 'source-map-loader'},
preprocessorLoader,
],
exclude: [
path.resolve(__dirname, 'node_modules'),
],
},
{
test: /\.tsx?$/,
use: [
{loader: 'ts-loader'},
preprocessorLoader,
]
},
]
},
};
};