[1.*] Webpack code splitting - wrong directory
See original GitHub issue- Laravel Mix Version: 1.0.6
- Node Version: 8.1.0
- NPM Version: 5.0.3
- Yarn Version: 0.21.3
- OS: Windows 10
Description:
With Laravel Mix 0.* modules created with webpack code splitting were automatically put in the public/js
directory. Now, with Mix 1.* it puts all the chunks in the public
directory(unless for each chunk I specify its name with js/
prefix).
Steps To Reproduce:
$ laravel new foo --dev
- Update Mix version (
0.*
to1.*
) inpackage.json
$ yarn
$ yarn add babel-preset-es2015 babel-preset-stage-2
(not sure here which one gives the ability to import dynamically)- Create
.babelrc
file:
{
"presets": ["es2015", "stage-2"]
}
- In
app.js
split the Example component to a separate chunk
// Replace this
Vue.component('example', require('./components/Example.vue'));
// With this
Vue.component('example', () => import('./components/Example.vue'));
$ yarn run development
The 0.js
file should appear in public
directory.
Possible fix:
In webpack.mix.js
add
mix.webpackConfig({
output: {
chunkFilename: 'js/[name].[chunkhash].js',
},
});
Is there a better way to fix this?
Issue Analytics
- State:
- Created 6 years ago
- Reactions:16
- Comments:36 (2 by maintainers)
Top Results From Across the Web
[1.*] Webpack code splitting - wrong directory · Issue #936
* it puts all the chunks in the public directory(unless for each chunk I specify its name with js/ prefix). Steps To Reproduce:...
Read more >Webpack, new chunk is loading in with wrong path
js is an unnamed chunk created by code splitting. It will be placed in the output:path mentioned above but will be referred in...
Read more >Code Splitting
Code splitting is one of the most compelling features of webpack. This feature allows you to split your code into various bundles which...
Read more >The 100% correct way to split your chunks with Webpack
Let's dive in. Bundle splitting. The idea behind bundle splitting is pretty simple. If you have one giant file, and change one line...
Read more >Understanding Webpack's Code Splitting Feature
If you bootstrap your React application with Create React App (CRA), then the webpack configuration generated by CRA already enables code ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This worked for me:
Ok, I got it working. I needed to specify where I have the public files in webpack configuration, by adding
publicPath
. Now it seems it loads the chunks correctly from/build/chunks/
on production site:Thanks @KKSzymanowski for your time and input, I really appreciate!