|
2 | 2 |
|
3 | 3 | 'use strict'; |
4 | 4 |
|
5 | | -const path = require('path'); |
| 5 | +const path = require('node:path'); |
6 | 6 |
|
7 | | -/**@type {import('webpack').Configuration}*/ |
8 | | -const config = { |
9 | | - target: 'node', |
10 | | - entry: './src/extension.mts', |
11 | | - output: { |
12 | | - path: path.resolve(__dirname, "dist"), |
13 | | - filename: 'extension.js', |
14 | | - libraryTarget: 'commonjs2', |
15 | | - devtoolModuleFilenameTemplate: '../[resource-path]', |
16 | | - }, |
17 | | - node: { |
18 | | - __dirname: false, |
19 | | - }, |
20 | | - devtool: 'source-map', |
21 | | - externals: { |
22 | | - vscode: "commonjs vscode" |
23 | | - }, |
24 | | - resolve: { |
25 | | - extensions: ['.mts', '.ts', '.mjs', '.js'], |
26 | | - mainFields: ['main', 'module'], |
27 | | - extensionAlias: { |
28 | | - '.mjs': ['.mts', '.mjs'], // allow imports written as ./file.mjs to resolve ./file.mts |
29 | | - '.js': ['.ts', '.js'], // allow imports written as ./file.js to resolve ./file.ts |
| 7 | +//@ts-ignore |
| 8 | +module.exports = (_env, argv) => { |
| 9 | + const isProd = argv.mode === 'production'; |
| 10 | + |
| 11 | + /** @type {import('webpack').Configuration} */ |
| 12 | + const config = { |
| 13 | + name: 'extension', |
| 14 | + target: 'node', |
| 15 | + entry: './src/extension.mts', |
| 16 | + mode: isProd ? 'production' : 'development', |
| 17 | + output: { |
| 18 | + path: path.resolve(__dirname, "dist"), |
| 19 | + filename: 'extension.js', |
| 20 | + libraryTarget: 'commonjs2', |
| 21 | + }, |
| 22 | + node: { |
| 23 | + __dirname: false, |
| 24 | + }, |
| 25 | + devtool: 'source-map', |
| 26 | + externals: { |
| 27 | + vscode: "commonjs vscode" |
30 | 28 | }, |
31 | | - }, |
32 | | - module: { |
33 | | - rules: [{ |
34 | | - test: /\.[cm]?ts$/, |
35 | | - exclude: /node_modules/, |
36 | | - use: [{ |
37 | | - // configure TypeScript loader: |
38 | | - // * enable sources maps for end-to-end source maps |
39 | | - loader: 'ts-loader', |
40 | | - options: { |
41 | | - compilerOptions: { |
42 | | - "inlineSourceMap": true, |
| 29 | + resolve: { |
| 30 | + extensions: ['.mts', '.ts', '.mjs', '.js'], |
| 31 | + mainFields: ['main', 'module'], |
| 32 | + extensionAlias: { |
| 33 | + '.mjs': ['.mts', '.mjs'], // allow imports written as ./file.mjs to resolve ./file.mts |
| 34 | + '.js': ['.ts', '.js'], // allow imports written as ./file.js to resolve ./file.ts |
| 35 | + }, |
| 36 | + }, |
| 37 | + module: { |
| 38 | + rules: [{ |
| 39 | + test: /\.[cm]?ts$/, |
| 40 | + exclude: /node_modules/, |
| 41 | + use: [{ |
| 42 | + // configure TypeScript loader: |
| 43 | + // * enable sources maps for end-to-end source maps |
| 44 | + loader: 'ts-loader', |
| 45 | + options: { |
| 46 | + transpileOnly: true |
43 | 47 | } |
44 | | - } |
| 48 | + }] |
| 49 | + }, { |
| 50 | + test: /.node$/, |
| 51 | + loader: 'node-loader', |
45 | 52 | }] |
46 | | - }, { |
47 | | - test: /.node$/, |
48 | | - loader: 'node-loader', |
49 | | - }] |
50 | | - }, |
51 | | - optimization: { |
52 | | - minimize: true |
53 | | - }, |
54 | | - stats: { |
55 | | - warnings: false |
56 | | - } |
57 | | -}; |
| 53 | + }, |
| 54 | + optimization: { |
| 55 | + minimize: isProd |
| 56 | + }, |
| 57 | + stats: { |
| 58 | + warnings: false |
| 59 | + } |
| 60 | + }; |
58 | 61 |
|
59 | | -const uninstallerEsm = { |
60 | | - name: 'uninstaller', |
61 | | - target: 'node', |
62 | | - mode: 'production', |
63 | | - entry: './vscodeUninstall.mjs', // your existing file with TLA |
64 | | - experiments: { outputModule: true, topLevelAwait: true }, |
65 | | - output: { |
66 | | - path: path.resolve(__dirname, 'dist'), |
67 | | - filename: 'vscodeUninstall.mjs', |
68 | | - library: { type: 'module' }, |
69 | | - chunkFormat: 'module', |
70 | | - clean: false, |
71 | | - }, |
72 | | - devtool: false, |
73 | | - resolve: { extensions: ['.mjs', '.js'] }, |
74 | | -}; |
| 62 | + /** @type {import('webpack').Configuration} */ |
| 63 | + const uninstallerEsm = { |
| 64 | + name: 'uninstaller', |
| 65 | + target: 'node', |
| 66 | + mode: 'production', |
| 67 | + entry: './vscodeUninstall.mjs', // your existing file with TLA |
| 68 | + experiments: { outputModule: true, topLevelAwait: true }, |
| 69 | + output: { |
| 70 | + path: path.resolve(__dirname, 'dist'), |
| 71 | + filename: 'vscodeUninstall.mjs', |
| 72 | + library: { type: 'module' }, |
| 73 | + chunkFormat: 'module', |
| 74 | + clean: false, |
| 75 | + }, |
| 76 | + devtool: false, |
| 77 | + resolve: { extensions: ['.mjs', '.js'] }, |
| 78 | + }; |
75 | 79 |
|
76 | | -// @ts-ignore |
77 | | -module.exports = [config, uninstallerEsm]; |
| 80 | + return [config, uninstallerEsm]; |
| 81 | +}; |
0 commit comments