-
Notifications
You must be signed in to change notification settings - Fork 3
/
webpack.config.js
100 lines (95 loc) · 3.3 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
const fs = require('fs');
const path = require('path');
const CopyPlugin = require('copy-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const { merge } = require('webpack-merge');
const outputPath = path.join(__dirname, 'dist');
fs.rmSync(outputPath, { recursive: true, force: true });
/** @type {(env: Record<string, string>) => import("webpack").Configuration} */
function getCommonConfig(env) {
const isDevelopment = Boolean(env.development);
return {
mode: isDevelopment ? 'development' : 'production',
devtool: isDevelopment ? 'cheap-module-source-map' : false,
resolve: { extensions: ['.js', '.jsx', '.ts', '.tsx'] },
module: {
rules: [
{
test: /\.(js|jsx|ts|tsx)$/,
use: 'babel-loader',
exclude: /node_modules/,
},
{
test: /\.css$/i,
use: [MiniCssExtractPlugin.loader, 'css-loader'],
},
{
test: /\.(png|jpg|gif)$/i,
use: [
{
loader: 'url-loader',
options: {
limit: 8192,
},
},
],
},
],
},
plugins: [new MiniCssExtractPlugin()],
};
}
module.exports = [
function popup(env) {
return merge(getCommonConfig(env), {
entry: { popup: './popup/index.js' },
output: { path: path.join(outputPath, 'popup') },
plugins: [
new HtmlWebpackPlugin({
template: './popup/index.html',
}),
new MiniCssExtractPlugin(),
],
});
},
function content(env) {
return merge(getCommonConfig(env), {
entry: {
content: './content/content.js',
inject: './content/inject.js',
},
output: { path: path.join(outputPath, 'content') },
plugins: [
new CopyPlugin({
patterns: [{ from: './content/slider.css', to: '.' }],
}),
],
});
},
function backgroundPage(env) {
return merge(getCommonConfig(env), {
entry: { background: './background-page/index.js' },
output: { path: path.join(outputPath, 'background-page') },
plugins: [
new CopyPlugin({
patterns: [
{ from: 'manifest.json', to: '../manifest.json' },
{ from: './assets/**/*', to: '..' },
{
from: './_locales/**/*',
to: '..',
},
{
from: './background-page/encoders/*',
to: './encoders/[name][ext]',
},
],
}),
new HtmlWebpackPlugin({
template: './background-page/index.html',
}),
],
});
},
];