Skip to content

Commit fc39d6f

Browse files
committed
bug #457 Conditionally add some logic to prevent accidental sourcemaps (weaverryan)
This PR was merged into the master branch. Discussion ---------- Conditionally add some logic to prevent accidental sourcemaps Fixes #454 Commits ------- 06d66b6 Conditionally add some logic to prevent accidental sourcemaps
2 parents 3bf5892 + 06d66b6 commit fc39d6f

File tree

2 files changed

+32
-7
lines changed

2 files changed

+32
-7
lines changed

lib/plugins/optimize-css-assets.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,19 @@ module.exports = function(webpackConfig) {
2020
const optimizePluginOptions = {
2121
// see: https://github.com/NMFR/optimize-css-assets-webpack-plugin/issues/53#issuecomment-400294569
2222
// we always use annotations: true, which is the setting if you're
23-
// outputting to a separate file because this plugin is only
23+
// outputting to a separate file. This plugin is only
2424
// used in production, and, in production, we always use the
2525
// source-map option (a separate file) in config-generator.
26-
cssProcessorOptions: {
27-
map: {
28-
inline: false,
29-
annotation: true,
30-
}
31-
}
26+
cssProcessorOptions: {}
3227
};
3328

29+
if (webpackConfig.useSourceMaps) {
30+
optimizePluginOptions.cssProcessorOptions.map = {
31+
inline: false,
32+
annotation: true,
33+
};
34+
}
35+
3436
return new OptimizeCSSAssetsPlugin(
3537
applyOptionsCallback(webpackConfig.optimizeCssPluginOptionsCallback, optimizePluginOptions)
3638
);

test/functional.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,29 @@ describe('Functional tests using webpack', function() {
621621
});
622622
});
623623

624+
it('Without enableSourceMaps(), there are no sourcemaps in production', (done) => {
625+
const config = createWebpackConfig('www/build', 'production');
626+
config.setPublicPath('/build');
627+
config.addEntry('main', './js/no_require');
628+
config.addStyleEntry('bg', './css/background_image.scss');
629+
config.addStyleEntry('font', './css/roboto_font.css');
630+
config.enableSassLoader();
631+
632+
testSetup.runWebpack(config, (webpackAssert) => {
633+
webpackAssert.assertOutputFileDoesNotHaveSourcemap(
634+
'main.js'
635+
);
636+
webpackAssert.assertOutputFileDoesNotHaveSourcemap(
637+
'font.css'
638+
);
639+
webpackAssert.assertOutputFileDoesNotHaveSourcemap(
640+
'bg.css'
641+
);
642+
643+
done();
644+
});
645+
});
646+
624647
it('Code splitting a scss file works', (done) => {
625648
const config = createWebpackConfig('www/build', 'dev');
626649
config.setPublicPath('/build');

0 commit comments

Comments
 (0)