-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathwebpack.config.js
95 lines (91 loc) · 3.5 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
const path = require('path');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const PostBuildManifestPlugin = require('./webpack-plugins/post-build-manifest-plugin');
const ReloadExtensionPlugin = require('./webpack-plugins/reload-extension-plugin');
const TouchManifestPlugin = require('./webpack-plugins/touch-manifest-plugin');
module.exports = (env, argv) => {
const isDevelopment = argv.mode === 'development';
const browserTarget = env.browser || 'chromium';
const manifestPath = `engines/${browserTarget}/manifest.json`;
return {
mode: isDevelopment ? 'development' : 'production',
entry: {
background: './src/background.ts',
content: './src/content.ts',
popup: './src/popup.tsx',
options: './src/options.tsx',
},
output: {
path: path.resolve(__dirname, 'dist'),
filename: '[name].js',
clean: true,
},
resolve: {
alias: {
'@': path.resolve(__dirname, 'src'),
},
extensions: ['.tsx', '.ts', '.js'],
},
module: {
rules: [
{
test: /\.(ts|tsx)$/,
use: 'ts-loader',
exclude: /node_modules/,
},
{
test: /\.module\.css$/,
use: [
MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
options: {
esModule: true,
modules: {
namedExport: true,
localIdentName: '[name]__[local]__[hash:base64:5]',
},
},
},
],
},
{
test: /\.css$/,
exclude: /\.module\.css$/,
use: [MiniCssExtractPlugin.loader, 'css-loader'],
},
],
},
plugins: [
new CleanWebpackPlugin(),
new HtmlWebpackPlugin({
template: 'public/options.html',
filename: 'options.html',
chunks: ['options'],
}),
new HtmlWebpackPlugin({
template: 'public/popup.html',
filename: 'popup.html',
chunks: ['popup'],
}),
new CopyWebpackPlugin({
patterns: [
{ from: manifestPath, to: 'manifest.json' },
{ from: 'public/icons/clinton16.png', to: 'icon16.png' },
{ from: 'public/icons/clinton32.png', to: 'icon32.png' },
{ from: 'public/icons/clinton48.png', to: 'icon48.png' },
{ from: 'public/icons/clinton128.png', to: 'icon128.png' },
{ from: 'public/images/alert.png', to: 'alert.png' },
],
}),
new MiniCssExtractPlugin(),
new PostBuildManifestPlugin(),
new ReloadExtensionPlugin(),
new TouchManifestPlugin(),
],
devtool: isDevelopment ? 'cheap-module-source-map' : 'source-map',
};
};