Skip to content

Commit 05b407f

Browse files
author
sky
committed
1 parent ab66874 commit 05b407f

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,22 @@ class ReactSSRDynamicChunkPlugin {
1111
apply(compiler) {
1212
compiler.hooks.emit.tap('ReactSSRDynamicChunkPlugin', (compilation, callback) => {
1313
const buildPath = compilation.options.output.path;
14-
15-
if (!fs.existsSync(buildPath)) {
16-
mkdirp.sync(buildPath);
17-
}
18-
1914
compilation.chunks.forEach(chunk => {
2015
if (!this.opts.chunk) {
2116
return;
2217
}
2318

19+
const chunks = chunk.files || [];
2420
const asyncChunks = chunk.getAllAsyncChunks();
25-
21+
const mainChunkFile = chunks.length > 0 ? chunks[0] : null;
22+
const mainChunkDir = mainChunkFile ? path.dirname(mainChunkFile) : null;
2623
asyncChunks && asyncChunks.forEach(asyncChunk => {
2724
asyncChunk.files.forEach(filename => {
28-
const filepath = path.join(buildPath, filename);
25+
const filepath = mainChunkDir ? path.join(buildPath, mainChunkDir, filename) : path.join(buildPath, filename);
26+
const filedir = path.dirname(filepath);
27+
if (!fs.existsSync(filedir)) {
28+
mkdirp.sync(filedir);
29+
}
2930
const source = compilation.assets[filename].source();
3031
fs.writeFileSync(filepath, source, 'utf8');
3132
});
@@ -36,4 +37,4 @@ class ReactSSRDynamicChunkPlugin {
3637
}
3738
}
3839

39-
module.exports = ReactSSRDynamicChunkPlugin;
40+
module.exports = ReactSSRDynamicChunkPlugin;

test/client.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ describe('client.test.js', () => {
8888
it('should dev hot test', () => {
8989
const builder = createBuilder({ env: 'dev', log: true });
9090
const webpackConfig = builder.create();
91-
expect(webpackConfig.entry['client.test'].length).to.equal(3);
91+
expect(webpackConfig.entry['client.test'].length).to.equal(4);
9292
});
9393
it('should html test', () => {
9494
const builder = createBuilder({

0 commit comments

Comments
 (0)