Skip to content

Commit b2af379

Browse files
authoredAug 16, 2019
fix: use "compressed" output when mode is "production" (#723)
1 parent 3545434 commit b2af379

File tree

4 files changed

+49
-1
lines changed

4 files changed

+49
-1
lines changed
 

‎src/getSassOptions.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ import cloneDeep from 'clone-deep';
55

66
import proxyCustomImporters from './proxyCustomImporters';
77

8+
function isProductionLikeMode(loaderContext) {
9+
return (
10+
loaderContext.mode === 'production' ||
11+
!loaderContext.mode ||
12+
loaderContext.minimize
13+
);
14+
}
15+
816
/**
917
* Derives the sass options from the loader context and normalizes its values with sane defaults.
1018
*
@@ -34,7 +42,7 @@ function getSassOptions(loaderContext, loaderOptions, content) {
3442
options.data = data ? data + os.EOL + content : content;
3543

3644
// opt.outputStyle
37-
if (!options.outputStyle && loaderContext.minimize) {
45+
if (!options.outputStyle && isProductionLikeMode(loaderContext)) {
3846
options.outputStyle = 'compressed';
3947
}
4048

‎test/__snapshots__/loader.test.js.snap

+16
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,22 @@ exports[`loader should work and ignore all css "@import" at-rules (node-sass) (s
282282
283283
exports[`loader should work and ignore all css "@import" at-rules (node-sass) (scss): warnings 1`] = `Array []`;
284284
285+
exports[`loader should work and output the "compressed" outputStyle when "mode" is production (dart-sass) (sass): errors 1`] = `Array []`;
286+
287+
exports[`loader should work and output the "compressed" outputStyle when "mode" is production (dart-sass) (sass): warnings 1`] = `Array []`;
288+
289+
exports[`loader should work and output the "compressed" outputStyle when "mode" is production (dart-sass) (scss): errors 1`] = `Array []`;
290+
291+
exports[`loader should work and output the "compressed" outputStyle when "mode" is production (dart-sass) (scss): warnings 1`] = `Array []`;
292+
293+
exports[`loader should work and output the "compressed" outputStyle when "mode" is production (node-sass) (sass): errors 1`] = `Array []`;
294+
295+
exports[`loader should work and output the "compressed" outputStyle when "mode" is production (node-sass) (sass): warnings 1`] = `Array []`;
296+
297+
exports[`loader should work and output the "compressed" outputStyle when "mode" is production (node-sass) (scss): errors 1`] = `Array []`;
298+
299+
exports[`loader should work and output the "compressed" outputStyle when "mode" is production (node-sass) (scss): warnings 1`] = `Array []`;
300+
285301
exports[`loader should work and use the "_index" file in package (dart-sass) (sass): errors 1`] = `Array []`;
286302
287303
exports[`loader should work and use the "_index" file in package (dart-sass) (sass): warnings 1`] = `Array []`;

‎test/helpers/compiler.js

+1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ export default function(fixture, config = {}, options = {}) {
5555
plugins: plugins(config),
5656
optimization: {
5757
runtimeChunk: false,
58+
minimizer: [],
5859
},
5960
// eslint-disable-next-line no-undefined
6061
resolve: config.resolve || undefined,

‎test/loader.test.js

+23
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,29 @@ describe('loader', () => {
525525
expect(stats.compilation.warnings).toMatchSnapshot('warnings');
526526
expect(stats.compilation.errors).toMatchSnapshot('errors');
527527
});
528+
529+
it(`should work and output the "compressed" outputStyle when "mode" is production (${implementationName}) (${syntax})`, async () => {
530+
const testId = getTestId('language', syntax);
531+
const options = {
532+
implementation: getImplementationByName(implementationName),
533+
};
534+
const stats = await compile(testId, {
535+
mode: 'production',
536+
loader: { options },
537+
});
538+
539+
expect(getCode(stats).content).toBe(
540+
getPureCode(
541+
testId,
542+
Object.assign({}, options, {
543+
outputStyle: 'compressed',
544+
})
545+
)
546+
);
547+
548+
expect(stats.compilation.warnings).toMatchSnapshot('warnings');
549+
expect(stats.compilation.errors).toMatchSnapshot('errors');
550+
});
528551
});
529552
});
530553
});

0 commit comments

Comments
 (0)
Please sign in to comment.