Skip to content

Commit cd91bf0

Browse files
committed
feat: Exclude DefaultConfig from webpack bundles & Modernize ESM Output (#8760)
1 parent 184e315 commit cd91bf0

3 files changed

Lines changed: 38 additions & 12 deletions

File tree

buildScripts/webpack/development/webpack.config.main.mjs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ const cwd = process.cwd(),
1212
buildTarget = requireJson(path.resolve(neoPath, 'buildScripts/webpack/development/buildTarget.json')),
1313
filenameConfig = requireJson(path.resolve(neoPath, 'buildScripts/webpack/json/build.json')),
1414
entry = {main: path.resolve(neoPath, filenameConfig.mainInput)},
15+
copyFile = path.resolve(neoPath, 'buildScripts/copyFile.mjs'),
1516
copyFolder = path.resolve(neoPath, 'buildScripts/copyFolder.mjs'),
17+
defConfigFrom = path.resolve(neoPath, 'src/DefaultConfig.mjs'),
18+
defConfigTo = path.resolve(cwd, buildTarget.folder, 'DefaultConfig.mjs'),
1619
faFrom = path.resolve(cwd, 'node_modules/@fortawesome/fontawesome-free'),
1720
faTo = path.resolve(cwd, buildTarget.folder, 'resources/fontawesome-free'),
1821
nodeCmd = os.platform().startsWith('win') ? 'node.exe' : 'node',
@@ -42,6 +45,16 @@ export default {
4245
entry,
4346
target : 'web',
4447

48+
experiments: {
49+
outputModule: true
50+
},
51+
52+
externals: {
53+
'./DefaultConfig.mjs': './DefaultConfig.mjs'
54+
},
55+
56+
externalsType: 'module',
57+
4558
plugins: [
4659
// Only for the non workspace based build scope, we have to ignore workspace related addons.
4760
// This might be a fit for webpack.ContextExclusionPlugin, but I did not get it working.
@@ -55,15 +68,19 @@ export default {
5568
}
5669
}),
5770
new WebpackHookPlugin({
58-
onBuildEnd: [`${nodeCmd} ${copyFolder} -s ${faFrom} -t ${faTo}`]
71+
onBuildEnd: [
72+
`${nodeCmd} ${copyFolder} -s ${faFrom} -t ${faTo}`,
73+
`${nodeCmd} ${copyFile} -s ${defConfigFrom} -t ${defConfigTo}`
74+
]
5975
}),
6076
...plugins
6177
],
6278

6379
output: {
6480
chunkFilename: 'chunks/main/[id].js',
6581
filename : filenameConfig.mainOutput,
82+
library : {type: 'module'},
6683
path : path.resolve(cwd, buildTarget.folder),
67-
publicPath : ''
84+
publicPath : 'auto'
6885
}
6986
};

buildScripts/webpack/production/webpack.config.main.mjs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,11 @@ const cwd = process.cwd(),
1313
filenameConfig = requireJson(path.resolve(neoPath, 'buildScripts/webpack/json/build.json')),
1414
entry = {main: path.resolve(neoPath, filenameConfig.mainInput)},
1515
copyFolder = path.resolve(neoPath, 'buildScripts/copyFolder.mjs'),
16+
defConfigFrom = path.resolve(neoPath, 'src/DefaultConfig.mjs'),
17+
defConfigTo = path.resolve(cwd, buildTarget.folder, 'DefaultConfig.mjs'),
1618
faFrom = path.resolve(cwd, 'node_modules/@fortawesome/fontawesome-free'),
1719
faTo = path.resolve(cwd, buildTarget.folder, 'resources/fontawesome-free'),
20+
minifyFile = path.resolve(neoPath, 'buildScripts/minifyFile.mjs'),
1821
nodeCmd = os.platform().startsWith('win') ? 'node.exe' : 'node',
1922
plugins = [];
2023

@@ -41,6 +44,16 @@ export default {
4144
entry,
4245
target: 'web',
4346

47+
experiments: {
48+
outputModule: true
49+
},
50+
51+
externals: {
52+
'./DefaultConfig.mjs': './DefaultConfig.mjs'
53+
},
54+
55+
externalsType: 'module',
56+
4457
plugins: [
4558
// Only for the non workspace based build scope, we have to ignore workspace related addons.
4659
// This might be a fit for webpack.ContextExclusionPlugin, but I did not get it working.
@@ -54,15 +67,19 @@ export default {
5467
}
5568
}),
5669
new WebpackHookPlugin({
57-
onBuildEnd: [`${nodeCmd} ${copyFolder} -s ${faFrom} -t ${faTo}`]
70+
onBuildEnd: [
71+
`${nodeCmd} ${copyFolder} -s ${faFrom} -t ${faTo}`,
72+
`${nodeCmd} ${minifyFile} ${defConfigFrom} ${defConfigTo}`
73+
]
5874
}),
5975
...plugins
6076
],
6177

6278
output: {
6379
chunkFilename: 'chunks/main/[id].js',
6480
filename : filenameConfig.mainOutput,
81+
library : {type: 'module'},
6582
path : path.resolve(cwd, buildTarget.folder),
66-
publicPath : ''
83+
publicPath : 'auto'
6784
}
6885
};

src/main/DeltaUpdates.mjs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,9 @@ class DeltaUpdates extends Base {
6767
construct(config) {
6868
super.construct(config);
6969

70-
let {environment} = NeoConfig;
71-
7270
if (NeoConfig.renderCountDeltas) {
7371
this.renderCountDeltas = true
7472
}
75-
76-
// We need different publicPath values for the main thread inside the webpack based dist envs,
77-
// depending on the hierarchy level of the app entry point
78-
if (environment === 'dist/development' || environment === 'dist/production') {
79-
__webpack_require__.p = NeoConfig.basePath.substring(6)
80-
}
8173
}
8274

8375
/**

0 commit comments

Comments
 (0)