forked from eamodio/vscode-find-related
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
106 lines (100 loc) · 2.34 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
101
102
103
104
105
106
'use strict';
/* eslint-disable @typescript-eslint/no-var-requires */
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const { CleanWebpackPlugin: CleanPlugin } = require('clean-webpack-plugin');
const CircularDependencyPlugin = require('circular-dependency-plugin');
const ForkTsCheckerPlugin = require('fork-ts-checker-webpack-plugin');
const TerserPlugin = require('terser-webpack-plugin');
module.exports = function(env, argv) {
env = env || {};
env.analyzeBundle = Boolean(env.analyzeBundle);
env.analyzeDeps = Boolean(env.analyzeDeps);
env.production = env.analyzeBundle || Boolean(env.production);
/**
* @type any[]
*/
const plugins = [
new CleanPlugin(),
new ForkTsCheckerPlugin({
async: false,
eslint: true
})
];
if (env.analyzeDeps) {
plugins.push(
new CircularDependencyPlugin({
cwd: __dirname,
exclude: /node_modules/,
failOnError: false,
onDetected: function({ module: webpackModuleRecord, paths, compilation }) {
if (paths.some(p => p.includes('container.ts'))) return;
compilation.warnings.push(new Error(paths.join(' -> ')));
}
})
);
}
if (env.analyzeBundle) {
plugins.push(new BundleAnalyzerPlugin());
}
return {
name: 'extension',
entry: './src/extension.ts',
mode: env.production ? 'production' : 'development',
target: 'node',
node: {
__dirname: false
},
devtool: 'source-map',
output: {
libraryTarget: 'commonjs2',
filename: 'extension.js'
},
optimization: {
minimizer: [
new TerserPlugin({
cache: true,
parallel: true,
sourceMap: env.production,
terserOptions: {
ecma: 8,
// Keep the class names otherwise @log won't provide a useful name
// eslint-disable-next-line @typescript-eslint/camelcase
keep_classnames: true,
module: true
}
})
]
},
externals: {
vscode: 'commonjs vscode'
},
module: {
rules: [
{
exclude: /node_modules|\.d\.ts$/,
test: /\.tsx?$/,
use: {
loader: 'ts-loader',
options: {
experimentalWatchApi: true,
transpileOnly: true
}
}
}
]
},
resolve: {
extensions: ['.ts', '.tsx', '.js', '.jsx', '.json']
},
plugins: plugins,
stats: {
all: false,
assets: true,
builtAt: true,
env: true,
errors: true,
timings: true,
warnings: true
}
};
};