-
Notifications
You must be signed in to change notification settings - Fork 607
/
webpack.config.js
70 lines (64 loc) · 2.04 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
/* eslint-env es6 */
'use strict';
const { PackageJsonLookup } = require('@rushstack/node-core-library');
const { PreserveDynamicRequireWebpackPlugin } = require('@rushstack/webpack-preserve-dynamic-require-plugin');
module.exports = () => {
const packageJson = PackageJsonLookup.loadOwnPackageJson(__dirname);
const externalDependencyNames = new Set([...Object.keys(packageJson.dependencies || {})]);
// Explicitly exclude @microsoft/rush-lib
externalDependencyNames.delete('@microsoft/rush-lib');
return {
context: __dirname,
mode: 'development', // So the output isn't minified
devtool: 'source-map',
entry: {
// Using CommonJS due to access of module.parent
index: `${__dirname}/lib-commonjs/index.js`,
loader: `${__dirname}/lib-commonjs/loader.js`
},
output: {
path: `${__dirname}/lib-shim`,
filename: '[name].js',
chunkFilename: 'chunks/[name].js',
library: {
type: 'commonjs2'
}
},
optimization: {
flagIncludedChunks: true,
concatenateModules: true,
providedExports: true,
usedExports: true,
sideEffects: true,
removeAvailableModules: true,
minimize: false,
realContentHash: true,
innerGraph: true
},
target: 'node',
plugins: [new PreserveDynamicRequireWebpackPlugin()],
externals: [
({ request }, callback) => {
let packageName;
let firstSlashIndex = request.indexOf('/');
if (firstSlashIndex === -1) {
packageName = request;
} else if (request.startsWith('@')) {
let secondSlash = request.indexOf('/', firstSlashIndex + 1);
if (secondSlash === -1) {
packageName = request;
} else {
packageName = request.substring(0, secondSlash);
}
} else {
packageName = request.substring(0, firstSlashIndex);
}
if (externalDependencyNames.has(packageName)) {
callback(null, `commonjs ${request}`);
} else {
callback();
}
}
]
};
};