-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathwebpack.config.js
88 lines (84 loc) · 3.01 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
const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const { CheckerPlugin } = require('awesome-typescript-loader');
const ChromeExtensionReloader = require('webpack-chrome-extension-reloader');
const locateContentScripts = require('./utils/locateContentScripts');
const sourceRootPath = path.join(__dirname, 'src');
const contentScriptsPath = path.join(sourceRootPath, 'ts', 'contentScripts');
const distRootPath = path.join(__dirname, 'dist');
const nodeEnv = process.env.NODE_ENV ? process.env.NODE_ENV : 'development';
const webBrowser = process.env.WEB_BROWSER ? process.env.WEB_BROWSER : 'chrome';
module.exports = {
entry: {
background: path.join(sourceRootPath, 'ts', 'background', 'index.ts'),
options: path.join(sourceRootPath, 'ts', 'options', 'index.tsx'),
popup: path.join(sourceRootPath, 'ts', 'popup', 'index.tsx'),
...locateContentScripts(contentScriptsPath)
},
output: {
path: distRootPath,
filename: '[name].js',
},
resolve: {
extensions: ['.js', '.ts', '.tsx', '.json'],
},
module: {
rules: [
{ test: /\.(js|ts|tsx)?$/, loader: "awesome-typescript-loader", exclude: /node_modules/ },
]
},
plugins: [
new CheckerPlugin(),
new HtmlWebpackPlugin({
template: path.join(sourceRootPath, 'html', 'options.html'),
inject: 'body',
filename: 'options.html',
title: 'Web Extension Starter - Options Page',
chunks: ['options'],
}),
new HtmlWebpackPlugin({
template: path.join(sourceRootPath, 'html', 'popup.html'),
inject: 'body',
filename: 'popup.html',
title: 'Web Extension Starter - Popup Page',
chunks: ['popup'],
}),
new CopyWebpackPlugin([
{
from: path.join(sourceRootPath, 'assets'),
to: path.join(distRootPath, 'assets'),
test: /\.(jpg|jpeg|png|gif|svg)?$/,
},
{
from: path.join(sourceRootPath, 'manifest.json'),
to: path.join(distRootPath, 'manifest.json'),
toType: 'file',
}
]),
new webpack.DefinePlugin({
'NODE_ENV': JSON.stringify(nodeEnv),
'WEB_BROWSER': JSON.stringify(webBrowser),
}),
],
}
if (nodeEnv === 'watch') {
module.exports.watch = true;
module.exports.plugins.push(
new ChromeExtensionReloader({
port: 9128,
reloadPage: true,
entries: {
background: 'background',
options: 'options',
popup: 'popup',
contentScript: ['counter'],
}
})
);
}
if (nodeEnv === 'production') {
module.exports.plugins.push(new CleanWebpackPlugin(distRootPath, { verbose: true, dry: false }));
}