-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.common.js
123 lines (119 loc) · 2.99 KB
/
webpack.common.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
const path = require('path');
const dotenv = require('dotenv');
dotenv.config();
const getAbsolutePath = (pathDir) => path.resolve(__dirname, pathDir);
const getHtmlPlugins = (chunks) => {
return chunks.map(
({ chunk, title }) =>
new HtmlPlugin({
template: getAbsolutePath('src/pages/Popup/index.html'),
title: `${title}`,
filename: `${chunk}.html`,
chunks: [chunk],
GA_KEY: process.env.REACT_APP_GA_KEY,
UA_KEY: process.env.REACT_APP_UA_KEY,
}),
);
};
const Dotenv = require('dotenv-webpack');
const { ESBuildMinifyPlugin } = require('esbuild-loader');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const CopyPlugin = require('copy-webpack-plugin');
const HtmlPlugin = require('html-webpack-plugin');
module.exports = {
entry: {
popup: getAbsolutePath('src/pages/Popup/index.tsx'),
background: getAbsolutePath('src/pages/Background/index.ts'),
productContent: getAbsolutePath('src/pages/Content/productContent/index.ts'),
sizeTableContent: getAbsolutePath('src/pages/Content/sizeTableContent/index.ts'),
getUserData: getAbsolutePath('src/pages/Content/getUserData/index.ts'),
},
output: {
filename: 'script/[name].js',
path: getAbsolutePath('build'),
},
cache: {
type: 'filesystem',
buildDependencies: {
config: [__filename],
},
},
module: {
rules: [
{
test: /\.ts(x?)$/,
exclude: /node_modules/,
loader: 'esbuild-loader',
options: {
loader: 'tsx',
target: 'esnext',
tsconfigRaw: require('./tsconfig.json'),
},
},
{
test: /\.css$/i,
use: ['style-loader', 'css-loader'],
},
{
test: /\.(png|jp(e*)g|svg|gif)$/,
use: [
{
loader: 'file-loader',
options: {
name: 'images/[hash]-[name].[ext]',
publicPath: '',
},
},
],
},
{
test: /\.(woff|woff2|eot|ttf|otf)$/i,
use: [
{
loader: 'url-loader',
options: {
limit: 10000,
fallback: 'file-loader',
},
},
],
},
],
},
resolve: {
extensions: ['.tsx', '.ts', '.js', '.json'],
alias: {
'@src': getAbsolutePath('./src'),
'@assets': getAbsolutePath('./assets'),
},
},
optimization: {
minimizer: [
new ESBuildMinifyPlugin({
target: 'es2015',
}),
],
},
performance: {
hints: false,
maxEntrypointSize: 512000,
maxAssetSize: 512000,
},
plugins: [
new Dotenv({
path: '.env',
}),
new CleanWebpackPlugin({
cleanOnceBeforeBuildPatterns: ['**/*', path.resolve(process.cwd(), 'build/**/*')],
}),
new CopyPlugin({
patterns: [
{
from: getAbsolutePath('src'),
to: getAbsolutePath('build'),
},
],
}),
...getHtmlPlugins([{ chunk: 'popup', title: 'Own-Size' }]),
],
};