forked from Azure/bicep
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.ts
128 lines (124 loc) · 3.62 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
import path from "path";
import webpack from "webpack";
import CopyPlugin from "copy-webpack-plugin";
import ForkTsCheckerWebpackPlugin from "fork-ts-checker-webpack-plugin";
import TerserPlugin from "terser-webpack-plugin";
const extensionConfig: webpack.Configuration = {
target: "node",
entry: "./src/extension.ts",
devtool: "source-map",
output: {
path: path.resolve(__dirname, "out"),
filename: "extension.js",
libraryTarget: "commonjs2",
devtoolModuleFilenameTemplate: "file:///[absolute-resource-path]",
},
externals: {
// the vscode-module is created on-the-fly and must be excluded. Add other modules that cannot be webpack'ed, 📖 -> https://webpack.js.org/configuration/externals/
vscode: "commonjs vscode",
// The following are optional dependencies of microsoft/vscode-azext-utils that cannot be resolved.
"applicationinsights-native-metrics":
"commonjs applicationinsights-native-metrics",
"@opentelemetry/tracing": "commonjs @opentelemetry/tracing",
},
optimization: {
minimizer: [
new TerserPlugin({
terserOptions: {
keep_classnames: true,
keep_fnames: true,
},
}),
],
},
module: {
rules: [
{
test: /\.ts$/,
loader: "esbuild-loader",
options: {
loader: "ts",
target: "es2019",
},
exclude: [/node_modules/, /visualizer\/app/, /test/],
},
],
},
plugins: [
new CopyPlugin({
patterns: [
{
from: "../textmate/bicep.tmlanguage",
to: path.join(__dirname, "syntaxes/bicep.tmlanguage"),
},
],
}) as { apply(...args: unknown[]): void },
new CopyPlugin({
patterns: [
{
from: "../textmate/language-configuration.json",
to: path.join(__dirname, "syntaxes/language-configuration.json"),
},
],
}) as { apply(...args: unknown[]): void },
new ForkTsCheckerWebpackPlugin(),
],
resolve: {
extensions: [".ts", ".js"],
},
};
const visualizerConfig: webpack.Configuration = {
target: "web",
entry: "./src/visualizer/app/components/index.tsx",
devtool: "source-map",
output: {
filename: "visualizer.js",
path: path.resolve(__dirname, "out"),
devtoolModuleFilenameTemplate: "file:///[absolute-resource-path]",
},
externals: {
"web-worker": "commonjs web-worker",
},
module: {
rules: [
{
test: /\.tsx?$/,
loader: "esbuild-loader",
options: {
loader: "tsx",
target: "es2019",
},
exclude: /node_modules/,
},
{
test: /\.svg$/,
use: "svg-inline-loader",
exclude: /node_modules/,
},
],
},
resolve: {
extensions: [".js", ".ts", ".tsx"],
},
plugins: [
// Since React 17 it's not necessary to do "import React from 'react';" anymore.
// This is needed for esbuild-loader to resolve react.
new webpack.ProvidePlugin({
React: "react",
}),
],
};
module.exports = (env: unknown, argv: { mode: string }) => {
if (argv.mode === "development") {
// "cheap-module-source-map" is almost 2x faster than "source-map",
// while it provides decent source map quality.
// Note that any "eval" options cannot be used because it will be blocked by
// the content security policy that we set in /visualizer/view.ts.
const developmentDevtool = "cheap-module-source-map";
extensionConfig.devtool = developmentDevtool;
visualizerConfig.devtool = developmentDevtool;
}
return [extensionConfig, visualizerConfig];
};