question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[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.* to 1.*) in package.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:closed
  • Created 6 years ago
  • Reactions:16
  • Comments:36 (2 by maintainers)

github_iconTop GitHub Comments

7reactions
silvioiannonecommented, Jul 19, 2017

This worked for me:

mix.webpackConfig({
    output: {
        chunkFilename: 'js/[name].js',
    }
});
6reactions
georgecocacommented, Sep 22, 2017

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:

let mix = require('laravel-mix');

if (mix.inProduction()) {
    mix.setPublicPath('public/build');
}

mix.webpackConfig({
    output: {
         chunkFilename: mix.inProduction() ? 'chunks/[name].[chunkhash].js' : 'chunks/[name].js',
         publicPath: mix.inProduction() ? '/build/' : '/'
    }
}

Thanks @KKSzymanowski for your time and input, I really appreciate!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found