|
3 | 3 | const path = require("path"); |
4 | 4 | const webpack = require("webpack"); |
5 | 5 |
|
6 | | -/**@type {import('webpack').Configuration}*/ |
7 | | -const config = { |
8 | | - entry: "./src/extension.ts", // the entry point of this extension, 📖 -> https://webpack.js.org/configuration/entry-context/ |
9 | | - devtool: "source-map", |
10 | | - externals: { |
11 | | - vscode: "commonjs vscode" |
12 | | - }, |
13 | | - node: { |
14 | | - __dirname: false // We need to support dirname to be able to load the language server |
15 | | - }, |
16 | | - plugins: [ |
17 | | - new webpack.ProvidePlugin({ |
18 | | - Buffer: ["buffer", "Buffer"] |
19 | | - }), |
20 | | - new webpack.DefinePlugin({ |
21 | | - PRODUCTION: JSON.stringify(process.env.NODE_ENV) |
22 | | - }) |
23 | | - ], |
24 | | - resolve: { |
25 | | - extensions: [".ts", ".js"], |
26 | | - alias: { |
27 | | - "universal-user-agent$": "universal-user-agent/dist-node/index.js" |
| 6 | +module.exports = (env, argv) => { |
| 7 | + /**@type {import('webpack').Configuration}*/ |
| 8 | + const config = { |
| 9 | + entry: "./src/extension.ts", // the entry point of this extension, 📖 -> https://webpack.js.org/configuration/entry-context/ |
| 10 | + devtool: "source-map", |
| 11 | + externals: { |
| 12 | + vscode: "commonjs vscode" |
28 | 13 | }, |
29 | | - fallback: { |
30 | | - buffer: require.resolve("buffer/"), |
31 | | - path: require.resolve("path-browserify"), |
32 | | - crypto: require.resolve("crypto-browserify"), |
33 | | - stream: require.resolve("stream-browserify"), |
34 | | - timers: require.resolve("timers-browserify") |
35 | | - } |
36 | | - }, |
37 | | - module: { |
38 | | - rules: [ |
39 | | - { |
40 | | - test: /\.ts$/, |
41 | | - exclude: /node_modules/, |
42 | | - use: [ |
43 | | - { |
44 | | - loader: "ts-loader", |
45 | | - options: { |
46 | | - compilerOptions: { |
47 | | - sourceMap: true |
| 14 | + node: { |
| 15 | + __dirname: false // We need to support dirname to be able to load the language server |
| 16 | + }, |
| 17 | + plugins: [ |
| 18 | + new webpack.ProvidePlugin({ |
| 19 | + Buffer: ["buffer", "Buffer"] |
| 20 | + }), |
| 21 | + new webpack.DefinePlugin({ |
| 22 | + PRODUCTION: argv.mode === "production" |
| 23 | + }) |
| 24 | + ], |
| 25 | + resolve: { |
| 26 | + extensions: [".ts", ".js"], |
| 27 | + alias: { |
| 28 | + "universal-user-agent$": "universal-user-agent/dist-node/index.js" |
| 29 | + }, |
| 30 | + fallback: { |
| 31 | + buffer: require.resolve("buffer/"), |
| 32 | + path: require.resolve("path-browserify"), |
| 33 | + crypto: require.resolve("crypto-browserify"), |
| 34 | + stream: require.resolve("stream-browserify"), |
| 35 | + timers: require.resolve("timers-browserify") |
| 36 | + } |
| 37 | + }, |
| 38 | + module: { |
| 39 | + rules: [ |
| 40 | + { |
| 41 | + test: /\.ts$/, |
| 42 | + exclude: /node_modules/, |
| 43 | + use: [ |
| 44 | + { |
| 45 | + loader: "ts-loader", |
| 46 | + options: { |
| 47 | + compilerOptions: { |
| 48 | + sourceMap: true |
| 49 | + } |
48 | 50 | } |
49 | 51 | } |
| 52 | + ] |
| 53 | + }, |
| 54 | + { |
| 55 | + test: /\.js$/, |
| 56 | + enforce: "pre", |
| 57 | + use: ["source-map-loader"] |
| 58 | + }, |
| 59 | + { |
| 60 | + test: /\.m?js$/, |
| 61 | + resolve: { |
| 62 | + fullySpecified: false // disable the behaviour |
50 | 63 | } |
51 | | - ] |
52 | | - }, |
53 | | - { |
54 | | - test: /\.js$/, |
55 | | - enforce: "pre", |
56 | | - use: ["source-map-loader"] |
57 | | - }, |
58 | | - { |
59 | | - test: /\.m?js$/, |
60 | | - resolve: { |
61 | | - fullySpecified: false // disable the behaviour |
| 64 | + }, |
| 65 | + { |
| 66 | + test: /\.node$/, |
| 67 | + use: "node-loader" |
62 | 68 | } |
63 | | - }, |
64 | | - { |
65 | | - test: /\.node$/, |
66 | | - use: "node-loader" |
67 | | - } |
68 | | - ] |
69 | | - }, |
70 | | - ignoreWarnings: [/Failed to parse source map/] |
71 | | -}; |
| 69 | + ] |
| 70 | + }, |
| 71 | + ignoreWarnings: [/Failed to parse source map/] |
| 72 | + }; |
72 | 73 |
|
73 | | -const nodeConfig = { |
74 | | - ...config, |
75 | | - target: "node", |
76 | | - output: { |
77 | | - path: path.resolve(__dirname, "dist"), |
78 | | - filename: "extension-node.js", |
79 | | - libraryTarget: "commonjs", |
80 | | - devtoolModuleFilenameTemplate: "../[resource-path]" |
81 | | - } |
82 | | -}; |
| 74 | + const nodeConfig = { |
| 75 | + ...config, |
| 76 | + target: "node", |
| 77 | + output: { |
| 78 | + path: path.resolve(__dirname, "dist"), |
| 79 | + filename: "extension-node.js", |
| 80 | + libraryTarget: "commonjs", |
| 81 | + devtoolModuleFilenameTemplate: "../[resource-path]" |
| 82 | + } |
| 83 | + }; |
83 | 84 |
|
84 | | -const webConfig = { |
85 | | - ...config, |
86 | | - target: "webworker", |
87 | | - output: { |
88 | | - path: path.resolve(__dirname, "dist"), |
89 | | - filename: "extension-web.js", |
90 | | - libraryTarget: "commonjs", |
91 | | - devtoolModuleFilenameTemplate: "../[resource-path]" |
92 | | - } |
93 | | -}; |
| 85 | + const webConfig = { |
| 86 | + ...config, |
| 87 | + target: "webworker", |
| 88 | + output: { |
| 89 | + path: path.resolve(__dirname, "dist"), |
| 90 | + filename: "extension-web.js", |
| 91 | + libraryTarget: "commonjs", |
| 92 | + devtoolModuleFilenameTemplate: "../[resource-path]" |
| 93 | + } |
| 94 | + }; |
94 | 95 |
|
95 | | -const serverConfig = { |
96 | | - entry: "./src/langserver.ts", |
97 | | - devtool: "inline-source-map", |
98 | | - externals: { |
99 | | - vscode: "commonjs vscode" |
100 | | - }, |
101 | | - plugins: [ |
102 | | - new webpack.ProvidePlugin({ |
103 | | - Buffer: ["buffer", "Buffer"] |
104 | | - }), |
105 | | - new webpack.DefinePlugin({ |
106 | | - PRODUCTION: JSON.stringify(process.env.NODE_ENV) |
107 | | - }) |
108 | | - ], |
109 | | - module: { |
110 | | - rules: [ |
111 | | - { |
112 | | - test: /\.ts$/, |
113 | | - use: [ |
114 | | - { |
115 | | - loader: "ts-loader", |
116 | | - options: { |
117 | | - compilerOptions: { |
118 | | - sourceMap: true |
| 96 | + const serverConfig = { |
| 97 | + entry: "./src/langserver.ts", |
| 98 | + devtool: "inline-source-map", |
| 99 | + externals: { |
| 100 | + vscode: "commonjs vscode" |
| 101 | + }, |
| 102 | + plugins: [ |
| 103 | + new webpack.ProvidePlugin({ |
| 104 | + Buffer: ["buffer", "Buffer"] |
| 105 | + }), |
| 106 | + new webpack.DefinePlugin({ |
| 107 | + PRODUCTION: JSON.stringify(process.env.NODE_ENV) |
| 108 | + }) |
| 109 | + ], |
| 110 | + module: { |
| 111 | + rules: [ |
| 112 | + { |
| 113 | + test: /\.ts$/, |
| 114 | + use: [ |
| 115 | + { |
| 116 | + loader: "ts-loader", |
| 117 | + options: { |
| 118 | + compilerOptions: { |
| 119 | + sourceMap: true |
| 120 | + } |
119 | 121 | } |
120 | 122 | } |
| 123 | + ], |
| 124 | + resolve: { |
| 125 | + fullySpecified: false |
| 126 | + } |
| 127 | + }, |
| 128 | + { |
| 129 | + test: /\.js$/, |
| 130 | + enforce: "pre", |
| 131 | + use: ["source-map-loader"] |
| 132 | + }, |
| 133 | + { |
| 134 | + test: /\.m?js$/, |
| 135 | + resolve: { |
| 136 | + fullySpecified: false // disable the behaviour |
121 | 137 | } |
122 | | - ], |
123 | | - resolve: { |
124 | | - fullySpecified: false |
125 | 138 | } |
| 139 | + ] |
| 140 | + }, |
| 141 | + ignoreWarnings: [/Failed to parse source map/], |
| 142 | + resolve: { |
| 143 | + extensions: [".ts", ".tsx", ".js"], |
| 144 | + extensionAlias: { |
| 145 | + ".ts": [".js", ".ts"], |
| 146 | + ".cts": [".cjs", ".cts"], |
| 147 | + ".mts": [".mjs", ".mts"] |
126 | 148 | }, |
127 | | - { |
128 | | - test: /\.js$/, |
129 | | - enforce: "pre", |
130 | | - use: ["source-map-loader"] |
131 | | - }, |
132 | | - { |
133 | | - test: /\.m?js$/, |
134 | | - resolve: { |
135 | | - fullySpecified: false // disable the behaviour |
136 | | - } |
| 149 | + fallback: { |
| 150 | + buffer: require.resolve("buffer/"), |
| 151 | + path: require.resolve("path-browserify") |
137 | 152 | } |
138 | | - ] |
139 | | - }, |
140 | | - ignoreWarnings: [/Failed to parse source map/], |
141 | | - resolve: { |
142 | | - extensions: [".ts", ".tsx", ".js"], |
143 | | - extensionAlias: { |
144 | | - ".ts": [".js", ".ts"], |
145 | | - ".cts": [".cjs", ".cts"], |
146 | | - ".mts": [".mjs", ".mts"] |
147 | | - }, |
148 | | - fallback: { |
149 | | - buffer: require.resolve("buffer/"), |
150 | | - path: require.resolve("path-browserify") |
151 | 153 | } |
152 | | - } |
153 | | -}; |
| 154 | + }; |
154 | 155 |
|
155 | | -const serverNodeConfig = { |
156 | | - ...serverConfig, |
157 | | - target: "node", |
158 | | - output: { |
159 | | - path: path.resolve(__dirname, "dist"), |
160 | | - filename: "server-node.js", |
161 | | - libraryTarget: "commonjs", |
162 | | - devtoolModuleFilenameTemplate: "../[resource-path]" |
163 | | - } |
164 | | -}; |
| 156 | + const serverNodeConfig = { |
| 157 | + ...serverConfig, |
| 158 | + target: "node", |
| 159 | + output: { |
| 160 | + path: path.resolve(__dirname, "dist"), |
| 161 | + filename: "server-node.js", |
| 162 | + libraryTarget: "commonjs", |
| 163 | + devtoolModuleFilenameTemplate: "../[resource-path]" |
| 164 | + } |
| 165 | + }; |
165 | 166 |
|
166 | | -const serverWebConfig = { |
167 | | - ...serverConfig, |
168 | | - target: "webworker", |
169 | | - output: { |
170 | | - path: path.resolve(__dirname, "dist"), |
171 | | - filename: "server-web.js", |
172 | | - devtoolModuleFilenameTemplate: "../[resource-path]" |
173 | | - } |
174 | | -}; |
| 167 | + const serverWebConfig = { |
| 168 | + ...serverConfig, |
| 169 | + target: "webworker", |
| 170 | + output: { |
| 171 | + path: path.resolve(__dirname, "dist"), |
| 172 | + filename: "server-web.js", |
| 173 | + devtoolModuleFilenameTemplate: "../[resource-path]" |
| 174 | + } |
| 175 | + }; |
175 | 176 |
|
176 | | -module.exports = [nodeConfig, webConfig, serverNodeConfig, serverWebConfig]; |
| 177 | + return [nodeConfig, webConfig, serverNodeConfig, serverWebConfig]; |
| 178 | +}; |
0 commit comments