|
| 1 | +//@ts-check |
| 2 | +'use strict'; |
| 3 | + |
| 4 | +/** @typedef {import('webpack').Configuration} WebpackConfig **/ |
| 5 | + |
| 6 | +const glob = require('glob'); |
| 7 | +const path = require('path'); |
| 8 | +const webpack = require('webpack'); |
| 9 | + |
| 10 | +/** @type {WebpackConfig} */ |
| 11 | +const webConfig = { |
| 12 | + context: __dirname, |
| 13 | + mode: 'none', // this leaves the source code as close as possible to the original (when packaging we set this to 'production') |
| 14 | + target: 'webworker', // web extensions run in a webworker context |
| 15 | + entry: { |
| 16 | + 'extension-web': './src/extension.ts', // source of the web extension main file |
| 17 | + 'test/suite/index-web': './src/test/suite/index-web.ts', // source of the web extension test runner |
| 18 | + }, |
| 19 | + output: { |
| 20 | + filename: '[name].js', |
| 21 | + path: path.join(__dirname, './dist'), |
| 22 | + libraryTarget: 'commonjs', |
| 23 | + }, |
| 24 | + resolve: { |
| 25 | + mainFields: ['browser', 'module', 'main'], // look for `browser` entry point in imported node modules |
| 26 | + extensions: ['.ts', '.js'], // support ts-files and js-files |
| 27 | + alias: { |
| 28 | + // provides alternate implementation for node module and source files |
| 29 | + }, |
| 30 | + fallback: { |
| 31 | + // Webpack 5 no longer polyfills Node.js core modules automatically. |
| 32 | + // see https://webpack.js.org/configuration/resolve/#resolvefallback |
| 33 | + // for the list of Node.js core module polyfills. |
| 34 | + assert: require.resolve('assert'), |
| 35 | + path: require.resolve("path-browserify"), |
| 36 | + util: require.resolve("util"), |
| 37 | + }, |
| 38 | + }, |
| 39 | + module: { |
| 40 | + rules: [ |
| 41 | + { |
| 42 | + test: /\.ts$/, |
| 43 | + exclude: /node_modules/, |
| 44 | + use: [ |
| 45 | + { |
| 46 | + loader: 'ts-loader', |
| 47 | + }, |
| 48 | + ], |
| 49 | + }, |
| 50 | + ], |
| 51 | + }, |
| 52 | + plugins: [ |
| 53 | + new webpack.ProvidePlugin({ |
| 54 | + process: 'process/browser', // provide a shim for the global `process` variable |
| 55 | + }), |
| 56 | + ], |
| 57 | + externals: { |
| 58 | + vscode: 'commonjs vscode', // ignored because it doesn't exist |
| 59 | + }, |
| 60 | + performance: { |
| 61 | + hints: false, |
| 62 | + }, |
| 63 | + devtool: 'nosources-source-map', // create a source map that points to the original source file |
| 64 | +}; |
| 65 | + |
| 66 | +/** @type {WebpackConfig} */ |
| 67 | +const nodeConfig = { |
| 68 | + context: __dirname, |
| 69 | + mode: 'none', // this leaves the source code as close as possible to the original (when packaging we set this to 'production') |
| 70 | + target: 'node', // extensions run in a node context |
| 71 | + entry: { |
| 72 | + 'extension-node': './src/extension.ts', // source of the node extension main file |
| 73 | + 'test/suite/index-node': './src/test/suite/index-node.ts', // source of the node extension test runner |
| 74 | + 'test/runTest': './src/test/runTest', // used to start the VS Code test runner (@vscode/test-electron) |
| 75 | + }, |
| 76 | + output: { |
| 77 | + filename: '[name].js', |
| 78 | + path: path.join(__dirname, './dist'), |
| 79 | + libraryTarget: 'commonjs', |
| 80 | + }, |
| 81 | + resolve: { |
| 82 | + mainFields: ['module', 'main'], |
| 83 | + extensions: ['.ts', '.js'], // support ts-files and js-files |
| 84 | + }, |
| 85 | + module: { |
| 86 | + rules: [ |
| 87 | + { |
| 88 | + test: /\.ts$/, |
| 89 | + exclude: /node_modules/, |
| 90 | + use: [ |
| 91 | + { |
| 92 | + loader: 'ts-loader', |
| 93 | + }, |
| 94 | + ], |
| 95 | + }, |
| 96 | + ], |
| 97 | + }, |
| 98 | + externals: { |
| 99 | + vscode: 'commonjs vscode', // ignored because it doesn't exist |
| 100 | + mocha: 'commonjs mocha', // don't bundle |
| 101 | + '@vscode/test-electron': 'commonjs @vscode/test-electron' // don't bundle |
| 102 | + }, |
| 103 | + performance: { |
| 104 | + hints: false, |
| 105 | + }, |
| 106 | + devtool: 'nosources-source-map', // create a source map that points to the original source file |
| 107 | +}; |
| 108 | + |
| 109 | +module.exports = [webConfig, nodeConfig]; |
0 commit comments