-
Notifications
You must be signed in to change notification settings - Fork 13
/
webpack.config.js
83 lines (81 loc) · 2.72 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
const path = require('path');
const webpack = require('webpack');
const pkg = require('./package.json');
/** @type {import('webpack').Configuration} */
module.exports = {
target: 'node',
entry: './src/extension.ts',
output: {
// Dirty workaround to allow us also building the `test` folder
path: path.resolve(__dirname, 'out/src'),
filename: 'extension.js',
libraryTarget: 'commonjs2',
devtoolModuleFilenameTemplate: '../[resource-path]',
},
optimization: {
splitChunks: false,
},
externalsPresets: {
node: true,
},
externals: [
{ vscode: 'commonjs vscode' },
// Dirty workaround to prevent modules being bundled,
// run `npm run webpack -- --mode development --stats-error-details` to update.
'@babel/helper-regex',
'@expo/dev-server',
'babel-preset-expo',
'emitter',
'fsevents',
/^webpack-hot-middleware/i,
/^webpack-plugin-serve/i,
/^webpack-dev-middleware/i,
// This library causes invalid JS, caused by https://github.com/jantimon/html-webpack-plugin/blob/8f8f7c53c4e4f822020d6da9de0304f8c23de08f/index.js#L133
// Webpack both shortens the `require: require` -> `require` and replaces require with an internal `__webpack_require(xxx)`.
// It's kinda stupid, `{ __webpack_require(xxx) }` is invalid, but we don't need this library within the bundle.
'html-webpack-plugin',
],
plugins: [
new webpack.DefinePlugin({
// Pass-through environment variables from current machine
'process.env.VSCODE_EXPO_DEBUG': JSON.stringify(process.env.VSCODE_EXPO_DEBUG),
'process.env.VSCODE_EXPO_TELEMETRY_KEY': JSON.stringify(
process.env.VSCODE_EXPO_TELEMETRY_KEY
),
// Avoid having to import the package.json in the extension
'process.env.EXTENSION_NAME': JSON.stringify(pkg.name),
'process.env.EXTENSION_VERSION': JSON.stringify(pkg.version),
'process.env.EXTENSION_ID': JSON.stringify(`${pkg.publisher}.${pkg.name}`),
}),
],
resolve: {
extensions: ['.ts', '.js', '.json'],
alias: {
// Importing Sucrase with esm support causes default exports to break.
// This forces the cjs import and use that as Sucrase in the bundle.
// see: https://github.com/webpack/webpack/issues/5756#issuecomment-907080675
sucrase: require.resolve('sucrase'),
},
},
module: {
parser: {
javascript: {
commonjsMagicComments: true,
},
},
rules: [
{
// Workaround for files within libraries using dynamic require
test: /\.md|\.map|LICENSE$/,
loader: 'raw-loader',
},
{
test: /\.(ts|js)$/,
loader: '@sucrase/webpack-loader',
options: {
transforms: ['typescript'],
},
},
],
},
};