Laravel-mix: [Sugestion] extractVueStyles new option

Created on 22 May 2017  路  5Comments  路  Source: JeffreyWay/laravel-mix

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?

stale

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:

  • extractVueStyles: string is not working, it always extract to a default 'vue-styles.css'
  • vue rendered page still has the injected styles that are supposed to be removed after extraction
  • extractVueStyles setting only works when no preprocessors are used on laravel-mix config (sass,stylus), it was coded that way but i don't know why.

All 5 comments

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:

  • extractVueStyles: string is not working, it always extract to a default 'vue-styles.css'
  • vue rendered page still has the injected styles that are supposed to be removed after extraction
  • extractVueStyles setting only works when no preprocessors are used on laravel-mix config (sass,stylus), it was coded that way but i don't know why.

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

stefensuhat picture stefensuhat  路  3Comments

wendt88 picture wendt88  路  3Comments

mstralka picture mstralka  路  3Comments

dtheb picture dtheb  路  3Comments

nezaboravi picture nezaboravi  路  3Comments