catamphetamine / universal-webpack

Isomorphic Webpack: both on client and server

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to config webpack-chunks.json path?

susan-github opened this issue · comments

Config the server.output look like './static/dist/server.js', the webpack-chunks.json file will be built to output path, because of the old project using ”clean-webpack-plugin“ plugin, so the dist folder will be removed which caused 'universal-webpack' find './static/dist' failed.

If you have any suggestions? If there has any way to config webpack-chunks.json path individually.

{ "server": { "input": "./src/server/index.js", "output": "./static/dist/server.js" }, "loadExternalModuleFileExtensions": ["css", "png", "jpg", "svg", "xml"], "silent": true, "chunk_info_filename": "webpack-chunks.json" }

The example project uses clean-webpack-plugin and it works.
https://github.com/catamphetamine/webpack-react-redux-server-side-render-example
That project builds server in build/server and client in build/assets and webpack-chunks.json is generated in build so it's not cleared: only build/assets is cleared.

Actually, my answer wasn't 100% correct: webpack-chunks.json is not output in build, it's output in build/assets and build/assets is cleaned:

image

I guess your issue is that you run clean plugin after universal-webpack plugin.

The code adds universal-webpack plugin after clean plugin so normally universal-webpack plugin can't run before clean.

configuration.plugins = configuration.plugins || []
configuration.plugins.push
(
// Add chunk filename info plugin
//
// Writes client-side build chunks filename info
// for later use inside server-side rendering code
// (`<script src=.../>` and `<link rel="style" href=.../>` tags)
//
// Cloning Webpack configuration here
// because `webpack-dev-server` seems to alter it
// by changing the already predefined `.output.path`.
//
new chunks_plugin(clone(configuration), { silent: settings.silent, chunk_info_filename: settings.chunk_info_filename })
)

Examine your resulting webpack config and see the order.