-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.ts
107 lines (99 loc) · 4.2 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
98
99
100
101
102
103
104
105
106
107
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
//
// Adapted from: https://github.com/microsoft/vscode-azuretools/blob/master/dev/src/webpack/getDefaultWebpackConfig.ts
//
import * as path from 'path';
import * as TerserPlugin from 'terser-webpack-plugin';
import * as webpack from 'webpack';
import { NLSBundlePlugin } from 'vscode-nls-dev/lib/webpack-bundler';
export const config: webpack.Configuration = {
devtool: 'nosources-source-map',
entry: './src/extension.ts',
externals: {
// Required by applicationinsights as a development dependency; not othewise needed.
'applicationinsights-native-metrics': 'applicationinsights-native-metrics',
// The vscode module is created on-the-fly and must be excluded.
vscode: 'commonjs vscode'
},
mode: 'none',
module: {
rules: [
{
exclude: /node_modules/,
test: /\.ts$/,
use: [
{
// vscode-nls-dev loader:
// * rewrite nls-calls
loader: 'vscode-nls-dev/lib/webpack-loader',
options: {
base: path.resolve(__dirname, 'src')
}
},
{
loader: 'ts-loader'
}]
},
]
},
node: {
__filename: true
},
optimization: {
minimizer: [
<webpack.WebpackPluginInstance><unknown>new TerserPlugin({
terserOptions: {
// Don't mangle class names. Otherwise parseError() will not recognize user cancelled errors (because their constructor name
// will match the mangled name, not UserCancelledError). Also makes debugging easier in minified code.
keep_classnames: true,
// Don't mangle function names. https://github.com/microsoft/vscode-azurestorage/issues/525
keep_fnames: true
}
})
]
},
output: {
devtoolModuleFilenameTemplate: '../[resource-path]',
filename: 'extension.js',
libraryTarget: 'commonjs2',
path: path.resolve(__dirname, 'dist'),
},
plugins: [
new NLSBundlePlugin('vscode-tye'),
// Fix warning:
// > WARNING in ./node_modules/ms-rest/lib/serviceClient.js 441:19-43
// > Critical dependency: the request of a dependency is an expression
// in this code:
// let data = require(packageJsonPath);
//
new webpack.ContextReplacementPlugin(
// Whenever there is a dynamic require that webpack can't analyze at all (i.e. resourceRegExp=/^\./), ...
/^\./,
// CONSIDER: Is there a type for the context argument? Can't seem to find one.
(context: any): void => {
// ... and the call was from within node_modules/ms-rest/lib...
if (/node_modules[/\\]ms-rest[/\\]lib/.test(context.context)) {
/* CONSIDER: Figure out how to make this work properly.
// ... tell webpack that the call may be loading any of the package.json files from the 'node_modules/azure-arm*' folders
// so it will include those in the package to be available for lookup at runtime
context.request = path.resolve(options.projectRoot, 'node_modules');
context.regExp = /azure-arm.*package\.json/;
*/
// In the meantime, just ignore the error by telling webpack we've solved the critical dependency issue.
// The consequences of ignoring this error are that
// the Azure SDKs (e.g. azure-arm-resource) don't get their info stamped into the user agent info for their calls.
for (const d of context.dependencies) {
if (d.critical) {
d.critical = false;
}
}
}
})
],
resolve: {
extensions: ['.ts', '.js', '.json']
},
target: 'node'
}
export default config;