-
Notifications
You must be signed in to change notification settings - Fork 677
Expand file tree
/
Copy pathwebpack.config.js
More file actions
148 lines (140 loc) · 5.09 KB
/
webpack.config.js
File metadata and controls
148 lines (140 loc) · 5.09 KB
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
137
138
139
140
141
142
143
144
145
146
147
148
'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-intermediate-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
],
module: {
rules: [
{
// These files have side effects (e.g. setting process.env variables) that must not
// be tree-shaken, even though they are only imported for their side effects.
// The package.json "sideEffects" field references the shipped folder names (lib-commonjs,
// lib-esm), but webpack reads from the intermediate build folders (lib-intermediate-esm).
test: /[\\/](SetRushLibPath|start|startx|start-pnpm)\.js$/,
sideEffects: true
}
]
},
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-intermediate-esm/index.js`,
start: `${__dirname}/lib-intermediate-esm/start.js`,
startx: `${__dirname}/lib-intermediate-esm/startx.js`,
'start-pnpm': `${__dirname}/lib-intermediate-esm/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-intermediate-esm',
outFolderName: 'lib-commonjs',
pathsToIgnore: ['utilities/prompts/SearchListPrompt.js'],
dTsFilesInputFolderName: 'lib-dts'
})
],
{
chunks: 'all',
minChunks: 1,
cacheGroups: {
commons: {
name: 'commons',
chunks: 'initial',
minChunks: 2
}
}
}
),
generateConfiguration({
[PathConstants.pnpmfileShimFilename]: {
import: `${__dirname}/lib-intermediate-esm/logic/pnpm/PnpmfileShim.js`,
...SCRIPT_ENTRY_OPTIONS
},
[PathConstants.subspacePnpmfileShimFilename]: {
import: `${__dirname}/lib-intermediate-esm/logic/pnpm/SubspaceGlobalPnpmfileShim.js`,
...SCRIPT_ENTRY_OPTIONS
},
[PathConstants.installRunScriptFilename]: {
import: `${__dirname}/lib-intermediate-esm/scripts/install-run.js`,
...SCRIPT_ENTRY_OPTIONS
},
[PathConstants.installRunRushScriptFilename]: {
import: `${__dirname}/lib-intermediate-esm/scripts/install-run-rush.js`,
...SCRIPT_ENTRY_OPTIONS
},
[PathConstants.installRunRushxScriptFilename]: {
import: `${__dirname}/lib-intermediate-esm/scripts/install-run-rushx.js`,
...SCRIPT_ENTRY_OPTIONS
},
[PathConstants.installRunRushPnpmScriptFilename]: {
import: `${__dirname}/lib-intermediate-esm/scripts/install-run-rush-pnpm.js`,
...SCRIPT_ENTRY_OPTIONS
}
})
];
return configurations;
};