-
-
Notifications
You must be signed in to change notification settings - Fork 461
/
webpack.config.js
126 lines (122 loc) · 3.11 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/* eslint-disable @typescript-eslint/no-var-requires */
"use strict";
// eslint-disable-next-line no-undef
const webpack = require("webpack");
// eslint-disable-next-line no-undef
const path = require("path");
// eslint-disable-next-line no-undef
const extensionPackage = require("./package.json");
const CopyPlugin = require("copy-webpack-plugin");
/**@type {import('webpack').Configuration}*/
const config = {
target: "node",
entry: "./src/extension.ts",
output: {
// eslint-disable-next-line no-undef
path: path.resolve(__dirname, "dist"),
filename: "extension.js",
libraryTarget: "commonjs2",
/* cspell: disable-next-line */
devtoolModuleFilenameTemplate: "../[resource-path]",
},
plugins: [
new webpack.EnvironmentPlugin({
EXTENSION_NAME: `${extensionPackage.publisher}.${extensionPackage.name}`,
EXTENSION_VERSION: extensionPackage.version,
}),
new CopyPlugin({
patterns: [{ from: "src/worker", to: "worker" }],
}),
],
/* cspell: disable-next-line */
devtool: "source-map",
externals: {
vscode: "commonjs vscode",
prettier: "commonjs prettier",
},
resolve: {
extensions: [".ts", ".js"],
},
module: {
rules: [
{
test: /\.ts$/,
exclude: /node_modules/,
use: [
{
loader: "ts-loader",
},
],
},
{
// vscode-nls-dev loader:
// * rewrite nls-calls
loader: "vscode-nls-dev/lib/webpack-loader",
options: {
// eslint-disable-next-line no-undef
base: path.join(__dirname, "src"),
},
},
],
},
};
const browserConfig = /** @type WebpackConfig */ {
mode: "none",
target: "webworker", // web extensions run in a webworker context
entry: {
"web-extension": "./src/extension.ts",
},
output: {
filename: "[name].js",
// eslint-disable-next-line no-undef
path: path.join(__dirname, "./dist"),
libraryTarget: "commonjs",
},
resolve: {
mainFields: ["module", "main"],
extensions: [".ts", ".js", ".mjs"], // support ts-files and js-files
alias: {
// replace the node based resolver with the browser version
"./ModuleResolver": "./BrowserModuleResolver",
},
fallback: {
// eslint-disable-next-line no-undef
path: require.resolve("path-browserify"),
// eslint-disable-next-line no-undef
util: require.resolve("util/"),
os: false,
},
},
module: {
rules: [
{
test: /\.ts$/,
exclude: /node_modules/,
use: [
{
loader: "ts-loader",
},
],
},
],
},
externals: {
vscode: "commonjs vscode", // ignored because it doesn't exist
},
performance: {
hints: false,
},
devtool: "source-map",
plugins: [
new webpack.ProvidePlugin({
process: "process/browser",
babel: "prettier/esm/parser-babel.mjs",
}),
new webpack.DefinePlugin({
"process.env": JSON.stringify({}),
"process.env.BROWSER_ENV": JSON.stringify("true"),
}),
],
};
// eslint-disable-next-line no-undef
module.exports = [config, browserConfig];