mirror of
https://github.com/flarum/framework.git
synced 2024-11-25 08:43:21 +08:00
fix: new webpack config doesn't work on windows (#4030)
This commit is contained in:
parent
29bb477efe
commit
c0d3d976fa
|
@ -6,6 +6,14 @@ const ConcatenatedModule = require('webpack/lib/optimize/ConcatenatedModule');
|
|||
class RegisterAsyncChunksPlugin {
|
||||
static registry = {};
|
||||
|
||||
processUrlPath(urlPath) {
|
||||
if (path.sep == "\\") {
|
||||
// separator on windows is "\", this will cause escape issues when used in url path.
|
||||
return urlPath.replace(/\\/g, '/');
|
||||
}
|
||||
return urlPath;
|
||||
}
|
||||
|
||||
apply(compiler) {
|
||||
compiler.hooks.thisCompilation.tap('RegisterAsyncChunksPlugin', (compilation) => {
|
||||
let alreadyOptimized = false;
|
||||
|
@ -63,6 +71,8 @@ class RegisterAsyncChunksPlugin {
|
|||
// Each line that has a webpackChunkName comment.
|
||||
[...module._source._value.matchAll(/.*\/\* webpackChunkName: .* \*\/.*/gm)].forEach(([match]) => {
|
||||
[...match.matchAll(/(.*?) webpackChunkName: '([^']*)'.*? \*\/ '([^']+)'.*?/gm)].forEach(([match, _, urlPath, importPath]) => {
|
||||
urlPath = this.processUrlPath(urlPath);
|
||||
|
||||
// Import path is relative to module.resource, so we need to resolve it
|
||||
const importPathResolved = path.resolve(path.dirname(module.resource), importPath);
|
||||
const thisComposerJson = require(path.resolve(process.cwd(), '../composer.json'));
|
||||
|
@ -118,7 +128,7 @@ class RegisterAsyncChunksPlugin {
|
|||
|
||||
// The path right after the src/ directory, without the extension.
|
||||
const regPathSep = `\\${path.sep}`;
|
||||
const urlPath = module.resource.replace(new RegExp(`.*${regPathSep}src${regPathSep}([^.]+)\..+`), '$1');
|
||||
const urlPath = this.processUrlPath(module.resource.replace(new RegExp(`.*${regPathSep}src${regPathSep}([^.]+)\..+`), '$1'));
|
||||
|
||||
if (!registrableModulesUrlPaths.has(urlPath)) {
|
||||
registrableModulesUrlPaths.set(urlPath, [relevantChunk.id, moduleId, namespace, urlPath]);
|
||||
|
|
|
@ -63,7 +63,12 @@ module.exports = function autoChunkNameLoader(source) {
|
|||
let chunkPath = relativePathToImport;
|
||||
|
||||
if (absolutePathToImport.includes('src')) {
|
||||
chunkPath = absolutePathToImport.split('src/')[1];
|
||||
chunkPath = absolutePathToImport.split(`src${path.sep}`)[1];
|
||||
}
|
||||
|
||||
if (path.sep == "\\") {
|
||||
// separator on windows is '\', the resolver only works with '/'.
|
||||
chunkPath = chunkPath.replace(/\\/g, '/');
|
||||
}
|
||||
|
||||
const webpackCommentOptions = {
|
||||
|
|
Loading…
Reference in New Issue
Block a user