Skip to content

Commit

Permalink
Fix prod css/sass sourcemaps (#1793) (#2282)
Browse files Browse the repository at this point in the history
* Fix prod css/sass sourcemaps (#1793)

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.

* Add cssnano to postcss plugins

* Allow cssNano config options to be specified

* remove comment
  • Loading branch information
bentaber committed Apr 2, 2020
1 parent a96f24f commit d4679d3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
9 changes: 1 addition & 8 deletions src/builder/webpack-default.js
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
8 changes: 8 additions & 0 deletions src/components/Preprocessor.js
Expand Up @@ -65,6 +65,14 @@ class Preprocessor {
);
}

if (Mix.inProduction()) {
plugins.push(
require('cssnano')({
preset: ['default', Config.cssNano]
})
);
}

return plugins;
})()
}
Expand Down

0 comments on commit d4679d3

Please sign in to comment.