|
8 | 8 | const path = require('path') |
9 | 9 | const webpack = require('webpack') |
10 | 10 |
|
11 | | -/**@type {import('webpack').Configuration}*/ |
12 | | -const config = { |
13 | | - target: 'node', // "webworker" for web or "node" for desktop |
| 11 | +{ |
| 12 | + require.resolve('assert') |
| 13 | +} |
| 14 | + |
| 15 | +/** @typedef {import('webpack').Configuration} WebpackConfig **/ |
| 16 | + |
| 17 | +function createExtensionConfig ({ target, output, plugins }) { |
| 18 | + return { |
| 19 | + target, |
| 20 | + entry: './src/extension.ts', |
| 21 | + output, |
| 22 | + devtool: 'source-map', |
| 23 | + externals: { |
| 24 | + vscode: 'commonjs vscode' // 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/ |
| 25 | + }, |
| 26 | + resolve: { |
| 27 | + mainFields: ['browser', 'module', 'main'], |
| 28 | + extensions: ['.ts'], |
| 29 | + alias: {}, |
| 30 | + fallback: {} |
| 31 | + }, |
| 32 | + module: { |
| 33 | + rules: [ |
| 34 | + { |
| 35 | + test: /\.ts$/, |
| 36 | + exclude: /node_modules/, |
| 37 | + use: [ |
| 38 | + { |
| 39 | + loader: 'ts-loader' |
| 40 | + } |
| 41 | + ] |
| 42 | + } |
| 43 | + ] |
| 44 | + }, |
| 45 | + plugins: plugins || [] |
| 46 | + } |
| 47 | +} |
14 | 48 |
|
15 | | - entry: './src/extension.ts', // the entry point of this extension, 📖 -> https://webpack.js.org/configuration/entry-context/ |
| 49 | +const nodeExtensionConfig = createExtensionConfig({ |
| 50 | + target: 'node', |
16 | 51 | output: { |
17 | | - // the bundle is stored in the 'dist' folder (check package.json), 📖 -> https://webpack.js.org/configuration/output/ |
18 | 52 | path: path.resolve(__dirname, 'dist'), |
19 | 53 | filename: 'extension.js', |
20 | 54 | libraryTarget: 'commonjs2', |
21 | 55 | devtoolModuleFilenameTemplate: '../[resource-path]' |
22 | 56 | }, |
23 | | - devtool: 'source-map', |
24 | | - externals: { |
25 | | - vscode: 'commonjs vscode' // 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/ |
26 | | - }, |
27 | | - resolve: { |
28 | | - // support reading TypeScript and JavaScript files, 📖 -> https://github.com/TypeStrong/ts-loader |
29 | | - mainFields: ['browser', 'module', 'main'], // look for `browser` entry point in imported node modules |
30 | | - extensions: ['.ts'], |
31 | | - alias: { |
32 | | - // provides alternate implementation for node module and source files |
33 | | - }, |
34 | | - fallback: { |
35 | | - // Webpack 5 no longer polyfills Node.js core modules automatically. |
36 | | - // see https://webpack.js.org/configuration/resolve/#resolvefallback |
37 | | - // for the list of Node.js core module polyfills. |
38 | | - path: false, |
39 | | - child_process: false, |
40 | | - util: false |
41 | | - // add other Node.js modules as needed |
42 | | - } |
| 57 | + plugins: [] |
| 58 | +}) |
| 59 | + |
| 60 | +const webExtensionConfig = createExtensionConfig({ |
| 61 | + target: 'webworker', |
| 62 | + output: { |
| 63 | + filename: '[name].js', |
| 64 | + path: path.join(__dirname, './dist/web'), |
| 65 | + libraryTarget: 'commonjs', |
| 66 | + devtoolModuleFilenameTemplate: '../../[resource-path]' |
43 | 67 | }, |
44 | | - module: { |
45 | | - rules: [ |
46 | | - { |
47 | | - test: /\.ts$/, |
48 | | - exclude: /node_modules/, |
49 | | - use: [ |
50 | | - { |
51 | | - loader: 'ts-loader' |
52 | | - } |
53 | | - ] |
54 | | - } |
55 | | - ] |
56 | | - } |
57 | | -} |
58 | | -module.exports = config |
| 68 | + plugins: [ |
| 69 | + new webpack.ProvidePlugin({ |
| 70 | + process: 'process/browser' |
| 71 | + }) |
| 72 | + ] |
| 73 | +}) |
| 74 | + |
| 75 | +module.exports = [webExtensionConfig, nodeExtensionConfig] |
0 commit comments