Skip to content

Commit

Permalink
Fix prod css/sass sourcemaps (laravel-mix#1793)
Browse files Browse the repository at this point in the history
Sass sourcemaps fail to generate in production builds due to cssnano
combined with OptimizeCSSAssetsPlugin.  Moving cssnano into
postcss-loader resolves issue.

More detail https://www.webfoobar.com/node/109

Note eval-source-maps still will not work at all for CSS, so
implementers must use `Mix.sourceMaps(true, 'source-map')` to allow
development builds to successfully generate sourcemaps.
  • Loading branch information
bentaber committed Nov 20, 2019
1 parent d432101 commit df3f71a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
9 changes: 1 addition & 8 deletions src/builder/webpack-default.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,7 @@ module.exports = function() {

optimization: Mix.inProduction()
? {
minimizer: [
new TerserPlugin(Config.terser),
new OptimizeCSSAssetsPlugin({
cssProcessorPluginOptions: {
preset: ['default', Config.cssNano]
}
})
]
minimizer: [new TerserPlugin(Config.terser)]
}
: {},

Expand Down
6 changes: 6 additions & 0 deletions src/components/Preprocessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ class Preprocessor {
);
}

if (Mix.inProduction()) {
require('cssnano')({
preset: 'default'
});
}

return plugins;
})()
}
Expand Down

0 comments on commit df3f71a

Please sign in to comment.