I'm currently using laravel-mix on a project that uses vue and vue-router lazy loading, among other things.
i found that if i set mix.options({ extractVueStyles: true }), all styles from lazy loaded routes are ignored from extraction.
I think it's fine to leave this as default behavior, but laravel-mix should have an option for extracting styles from all chunks. I fixed my "problem" manually editing laravel-mix/src/Vue/ExtractTextPluginFactory.js:L35
changed:
return new WebpackExtractPlugin(this.outputPath());
to:
return new WebpackExtractPlugin({filename: this.outputPath(), allChunks: true});
maybe we could add another config option like mix.options({ extractVueStyles: true, allChunks: true}) or something?
I'm instead wondering if allChunks: true should be the default. Is there any good reason for it not to be?
i think in some cases, it might be useful to leave styles on async components/routes, but i can't talk for everybody, i'm happy with either option :)
As mentioned on https://webpack.js.org/plugins/extract-text-webpack-plugin/#options allChunks is required "when using CommonsChunkPlugin and there are extracted chunks (from
ExtractTextPlugin.extract) in the commons chunk."
This was triggering webpack/webpack#959 in my project, where the initial build worked fine, but automatic rebuilds (running watch) failed.
I couldn't find a good way to add this option short of modifying the webpack-rules.js file directly. I could add my own ExtractTextPlugin instance in mix.webpackConfig instead of using extractVueStyles, but I would rather not do that and lose all the rules/loader setup.
after upgrading laravel-mix, i had to figure around to get this working again, there are some bugs but it really extracts to an external file:
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Most helpful comment
after upgrading laravel-mix, i had to figure around to get this working again, there are some bugs but it really extracts to an external file: