This repository has been archived by the owner on Mar 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 24
/
webpack.common.js
74 lines (72 loc) · 2.44 KB
/
webpack.common.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
const webpack = require('webpack');
const CopyPlugin = require('copy-webpack-plugin');
const path = require('path');
const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');
//@ts-check
/** @typedef {import('webpack').Configuration} WebpackConfig **/
/** @type WebpackConfig */
module.exports = {
target: 'node',
entry: {
extension: './src/extension.ts',
},
output: {
path: path.join(__dirname, 'out', 'src'),
filename: '[name].js',
libraryTarget: 'commonjs2',
},
externals: function ({context, request}, callback) {
if (/^vscode$/.test(request)) {
return callback(null, 'commonjs ' + request);
} else if (/^ganache$/.test(request)) {
// The Debugger uses `Environment.detect` to set the proper chain Id among other things.
// However, `@truffle/environment` depends on `ganache` to implement other methods,
// but it is not used in `detect`.
// We do not want to include `ganache` in the bundle, since it has two major drawbacks:
// bundle size and loaders issue related to native code.
// Thus, setting `ganache` as external allows to exclude it from the bundle.
// See PR https://github.com/trufflesuite/vscode-ext/pull/261 for more details.
return callback(null, 'require ("' + request + '")');
} else if (/^prettier$/.test(request)) {
// `prettier` is actually not used by the extension.
// It's included because there is transitive dependency through `@truffle#resolver#abi-to-sol#prettier`.
// See PR https://github.com/trufflesuite/vscode-ext/pull/270 for more details.
return callback(null, 'require ("' + request + '")');
} else if (/^electron$/.test(request)) {
return callback(null, 'require ("' + request + '")');
}
callback();
},
resolve: {
alias: {
'original-require': require.resolve('./polyfills/original-require'),
},
// .json is added to prevent import error from /node_modules/got/index.js
extensions: ['.ts', '.js', '.json'],
plugins: [
new TsconfigPathsPlugin({
logInfoToStdOut: true,
}),
],
},
module: {
rules: [
{
test: /\.ts$/,
exclude: /node_modules/,
loader: 'ts-loader',
options: {
transpileOnly: true,
},
},
],
},
plugins: [
new CopyPlugin({
patterns: [{from: './src/helpers/checkTruffleConfigTemplate.js', to: './'}],
}),
],
node: {
__dirname: false,
},
};