Skip to content

Commit fda1d13

Browse files
author
sky
committed
fix: ssr render async load component file path easy-team/egg-react-webpack-boilerplate#44
1 parent b8daada commit fda1d13

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

config/plugin/react-ssr-dynamic-chunk-webpack-plugin/index.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,23 @@ class ReactSSRDynamicChunkPlugin {
1212
compiler.hooks.emit.tap('ReactSSRDynamicChunkPlugin', (compilation, callback) => {
1313
const buildPath = compilation.options.output.path;
1414

15-
if (!fs.existsSync(buildPath)) {
16-
mkdirp.sync(buildPath);
17-
}
1815

1916
compilation.chunks.forEach(chunk => {
2017
if (!this.opts.chunk) {
2118
return;
2219
}
2320

21+
const chunks = chunk.files || [];
2422
const asyncChunks = chunk.getAllAsyncChunks();
25-
23+
const mainChunkFile = chunks.length > 0 ? chunks[0] : null;
24+
const mainChunkDir = mainChunkFile ? path.dirname(mainChunkFile) : null;
2625
asyncChunks && asyncChunks.forEach(asyncChunk => {
2726
asyncChunk.files.forEach(filename => {
28-
const filepath = path.join(buildPath, filename);
27+
const filepath = mainChunkDir ? path.join(buildPath, mainChunkDir, filename) : path.join(buildPath, filename);
28+
const filedir = path.dirname(filepath);
29+
if (!fs.existsSync(filedir)) {
30+
mkdirp.sync(filedir);
31+
}
2932
const source = compilation.assets[filename].source();
3033
fs.writeFileSync(filepath, source, 'utf8');
3134
});

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@easy-team/easywebpack-react",
3-
"version": "4.1.0",
3+
"version": "4.1.1",
44
"description": "React client render and server side render build solution for Webpack",
55
"keywords": [
66
"webpack",

0 commit comments

Comments
 (0)