fix: ensure compiled flecks are moved to their own chunk
This commit is contained in:
parent
b0ff466a11
commit
e3a7f7390b
2
TODO.md
2
TODO.md
|
@ -30,7 +30,7 @@
|
||||||
- [ ] add building to publish process ...
|
- [ ] add building to publish process ...
|
||||||
- [ ] @babel/register@7.18.x has a bug
|
- [ ] @babel/register@7.18.x has a bug
|
||||||
- [ ] `$flecks/db/sequelize` should be `$flecks/db.sequelize`
|
- [ ] `$flecks/db/sequelize` should be `$flecks/db.sequelize`
|
||||||
- [ ] `url()` in styles breaks HMR
|
- [x] `url()` in styles breaks HMR
|
||||||
# Next
|
# Next
|
||||||
|
|
||||||
# Webpack 5
|
# Webpack 5
|
||||||
|
|
|
@ -575,6 +575,7 @@ export default class ServerFlecks extends Flecks {
|
||||||
debugSilly('%s runtime de-externalized %s, alias: %s', runtime, fleck, alias);
|
debugSilly('%s runtime de-externalized %s, alias: %s', runtime, fleck, alias);
|
||||||
});
|
});
|
||||||
// Set up compilation at each root.
|
// Set up compilation at each root.
|
||||||
|
const compiledPaths = [];
|
||||||
Array.from(new Set(
|
Array.from(new Set(
|
||||||
needCompilation
|
needCompilation
|
||||||
.map(([fleck]) => fleck)
|
.map(([fleck]) => fleck)
|
||||||
|
@ -584,6 +585,8 @@ export default class ServerFlecks extends Flecks {
|
||||||
const resolved = dirname(R.resolve(join(root, 'package.json')));
|
const resolved = dirname(R.resolve(join(root, 'package.json')));
|
||||||
const sourcepath = this.constructor.sourcepath(resolved);
|
const sourcepath = this.constructor.sourcepath(resolved);
|
||||||
const sourceroot = join(sourcepath, '..');
|
const sourceroot = join(sourcepath, '..');
|
||||||
|
compiledPaths.push(sourceroot);
|
||||||
|
// @todo Ideally the fleck's 3rd party modules would be externalized.
|
||||||
// Alias this compiled fleck's `node_modules` to the root `node_modules`.
|
// Alias this compiled fleck's `node_modules` to the root `node_modules`.
|
||||||
config.resolve.alias[join(sourceroot, 'node_modules')] = join(FLECKS_CORE_ROOT, 'node_modules');
|
config.resolve.alias[join(sourceroot, 'node_modules')] = join(FLECKS_CORE_ROOT, 'node_modules');
|
||||||
const configFile = this.buildConfig('babel.config.js');
|
const configFile = this.buildConfig('babel.config.js');
|
||||||
|
@ -611,6 +614,24 @@ export default class ServerFlecks extends Flecks {
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
const compiledPathsRegex = new RegExp(
|
||||||
|
`(?:${compiledPaths.map((path) => path.replace(/[\\/]/g, '[\\/]')).join('|')})`,
|
||||||
|
);
|
||||||
|
if (!config.optimization) {
|
||||||
|
config.optimization = {};
|
||||||
|
}
|
||||||
|
if (!config.optimization.splitChunks) {
|
||||||
|
config.optimization.splitChunks = {};
|
||||||
|
}
|
||||||
|
if (!config.optimization.splitChunks.cacheGroups) {
|
||||||
|
config.optimization.splitChunks.cacheGroups = {};
|
||||||
|
}
|
||||||
|
config.optimization.splitChunks.cacheGroups.flecksCompiled = {
|
||||||
|
chunks: 'all',
|
||||||
|
enforce: true,
|
||||||
|
priority: 100,
|
||||||
|
test: compiledPathsRegex,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user