forked from microsoft/rushstack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
136 lines (128 loc) · 4.41 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
'use strict';
const webpack = require('webpack');
const { PackageJsonLookup } = require('@rushstack/node-core-library');
const { PreserveDynamicRequireWebpackPlugin } = require('@rushstack/webpack-preserve-dynamic-require-plugin');
const { DeepImportsPlugin } = require('@rushstack/webpack-deep-imports-plugin');
const PathConstants = require('./lib-commonjs/utilities/PathConstants');
const SCRIPT_ENTRY_OPTIONS = {
filename: `${PathConstants.scriptsFolderName}/[name]`
};
module.exports = () => {
const packageJson = PackageJsonLookup.loadOwnPackageJson(__dirname);
const externalDependencyNames = new Set([
...Object.keys(packageJson.dependencies || {}),
...Object.keys(packageJson.peerDependencies || {}),
...Object.keys(packageJson.optionalDependencies || {}),
...Object.keys(packageJson.devDependencies || {})
]);
function generateConfiguration(entry, extraPlugins = [], splitChunks = undefined) {
return {
context: __dirname,
mode: 'development', // So the output isn't minified
devtool: 'source-map',
entry,
output: {
path: `${__dirname}/dist`,
filename: '[name].js',
chunkFilename: 'chunks/[name].js',
library: {
type: 'commonjs2'
}
},
target: 'node',
plugins: [
new PreserveDynamicRequireWebpackPlugin(),
new webpack.ids.DeterministicModuleIdsPlugin({
maxLength: 6
}),
...extraPlugins
],
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();
}
}
],
optimization: {
splitChunks
}
};
}
const configurations = [
generateConfiguration(
{
'rush-lib': `${__dirname}/lib-esnext/index.js`,
start: `${__dirname}/lib-esnext/start.js`,
startx: `${__dirname}/lib-esnext/startx.js`,
'start-pnpm': `${__dirname}/lib-esnext/start-pnpm.js`
},
[
new DeepImportsPlugin({
// A manifest will be produced for each entry point, so since this compilation has multiple entry points,
// it needs to specify a template for the manifest filename.
// Otherwise webpack will throw an error about multiple writes to the same manifest file.
path: `${__dirname}/temp/build/webpack-dll/[name].json`,
inFolderName: 'lib-esnext',
outFolderName: 'lib',
pathsToIgnore: ['utilities/prompts/SearchListPrompt.js'],
dTsFilesInputFolderName: 'lib-commonjs'
})
],
{
chunks: 'all',
minChunks: 1,
cacheGroups: {
commons: {
name: 'commons',
chunks: 'initial',
minChunks: 2
}
}
}
),
generateConfiguration({
[PathConstants.pnpmfileShimFilename]: {
import: `${__dirname}/lib-esnext/logic/pnpm/PnpmfileShim.js`,
...SCRIPT_ENTRY_OPTIONS
},
[PathConstants.subspacePnpmfileShimFilename]: {
import: `${__dirname}/lib-esnext/logic/pnpm/SubspaceGlobalPnpmfileShim.js`,
...SCRIPT_ENTRY_OPTIONS
},
[PathConstants.installRunScriptFilename]: {
import: `${__dirname}/lib-esnext/scripts/install-run.js`,
...SCRIPT_ENTRY_OPTIONS
},
[PathConstants.installRunRushScriptFilename]: {
import: `${__dirname}/lib-esnext/scripts/install-run-rush.js`,
...SCRIPT_ENTRY_OPTIONS
},
[PathConstants.installRunRushxScriptFilename]: {
import: `${__dirname}/lib-esnext/scripts/install-run-rushx.js`,
...SCRIPT_ENTRY_OPTIONS
},
[PathConstants.installRunRushPnpmScriptFilename]: {
import: `${__dirname}/lib-esnext/scripts/install-run-rush-pnpm.js`,
...SCRIPT_ENTRY_OPTIONS
}
})
];
return configurations;
};