-
Notifications
You must be signed in to change notification settings - Fork 3
/
webpack.config.ts
97 lines (86 loc) · 2.37 KB
/
webpack.config.ts
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
import path from 'path';
import webpack from 'webpack';
import { CleanWebpackPlugin } from 'clean-webpack-plugin';
import { VueLoaderPlugin } from 'vue-loader';
import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer';
import { fileURLToPath } from 'url';
import { EsbuildPlugin } from 'esbuild-loader';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
export default function (
env: string,
op: { mode: webpack.Configuration['mode'] }
): webpack.Configuration {
const isProd = op.mode === 'production';
console.log('⌥', env, op.mode);
if (!isProd) {
console.log('Bundle anayser available at:', 'http://127.0.0.1:8888');
}
return {
mode: op.mode,
entry: {
'jsdiff-devtools': './src/jsdiff-devtools.ts',
'jsdiff-panel': './src/jsdiff-panel.js',
'jsdiff-proxy': './src/jsdiff-proxy.ts',
'jsdiff-console': './src/jsdiff-console.ts',
'firefox/jsdiff-background': './src/firefox/background-script.ts',
},
output: {
filename: '[name].js',
path: path.resolve(__dirname, 'bundle/js'),
},
resolve: {
extensions: ['.ts', '.js'],
modules: [path.resolve(__dirname, 'src/js'), 'node_modules'],
alias: {
'@': path.resolve(__dirname, 'src'),
},
},
plugins: [
new CleanWebpackPlugin(),
new VueLoaderPlugin(),
isProd
? () => {}
: new BundleAnalyzerPlugin({
// http://127.0.0.1:8888
openAnalyzer: false,
logLevel: 'silent',
}),
new webpack.DefinePlugin({
__VUE_OPTIONS_API__: 'false',
__VUE_PROD_DEVTOOLS__: 'false',
__VUE_PROD_HYDRATION_MISMATCH_DETAILS__: 'false',
}),
],
module: {
rules: [
{
test: /\.tsx?$/,
loader: 'esbuild-loader',
options: {
loader: 'ts',
target: 'es2022',
},
},
{
test: /\.vue$/,
loader: 'vue-loader',
},
{
test: /\.(scss|css)$/,
use: ['style-loader', 'css-loader', 'sass-loader'],
},
{
test: /\.svg/,
type: 'asset/resource',
},
],
},
optimization: {
splitChunks: false,
minimize: isProd,
minimizer: [new EsbuildPlugin()],
},
devtool: isProd ? false : 'source-map',
};
}