Skip to content

Commit

Permalink
fix: ssr render async load component file path easy-team/egg-react-we…
Browse files Browse the repository at this point in the history
  • Loading branch information
sky committed Nov 20, 2019
1 parent b8daada commit fda1d13
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
13 changes: 8 additions & 5 deletions config/plugin/react-ssr-dynamic-chunk-webpack-plugin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,23 @@ class ReactSSRDynamicChunkPlugin {
compiler.hooks.emit.tap('ReactSSRDynamicChunkPlugin', (compilation, callback) => {
const buildPath = compilation.options.output.path;

if (!fs.existsSync(buildPath)) {
mkdirp.sync(buildPath);
}

compilation.chunks.forEach(chunk => {
if (!this.opts.chunk) {
return;
}

const chunks = chunk.files || [];
const asyncChunks = chunk.getAllAsyncChunks();

const mainChunkFile = chunks.length > 0 ? chunks[0] : null;
const mainChunkDir = mainChunkFile ? path.dirname(mainChunkFile) : null;
asyncChunks && asyncChunks.forEach(asyncChunk => {
asyncChunk.files.forEach(filename => {
const filepath = path.join(buildPath, filename);
const filepath = mainChunkDir ? path.join(buildPath, mainChunkDir, filename) : path.join(buildPath, filename);
const filedir = path.dirname(filepath);
if (!fs.existsSync(filedir)) {
mkdirp.sync(filedir);
}
const source = compilation.assets[filename].source();
fs.writeFileSync(filepath, source, 'utf8');
});
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@easy-team/easywebpack-react",
"version": "4.1.0",
"version": "4.1.1",
"description": "React client render and server side render build solution for Webpack",
"keywords": [
"webpack",
Expand Down

0 comments on commit fda1d13

Please sign in to comment.