Skip to content

Commit

Permalink
fix: use "compressed" output when mode is "production" (#723)
Browse files Browse the repository at this point in the history
  • Loading branch information
evilebottnawi authored Aug 16, 2019
1 parent 3545434 commit b2af379
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/getSassOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ import cloneDeep from 'clone-deep';

import proxyCustomImporters from './proxyCustomImporters';

function isProductionLikeMode(loaderContext) {
return (
loaderContext.mode === 'production' ||
!loaderContext.mode ||
loaderContext.minimize
);
}

/**
* Derives the sass options from the loader context and normalizes its values with sane defaults.
*
Expand Down Expand Up @@ -34,7 +42,7 @@ function getSassOptions(loaderContext, loaderOptions, content) {
options.data = data ? data + os.EOL + content : content;

// opt.outputStyle
if (!options.outputStyle && loaderContext.minimize) {
if (!options.outputStyle && isProductionLikeMode(loaderContext)) {
options.outputStyle = 'compressed';
}

Expand Down
16 changes: 16 additions & 0 deletions test/__snapshots__/loader.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,22 @@ exports[`loader should work and ignore all css "@import" at-rules (node-sass) (s
exports[`loader should work and ignore all css "@import" at-rules (node-sass) (scss): warnings 1`] = `Array []`;
exports[`loader should work and output the "compressed" outputStyle when "mode" is production (dart-sass) (sass): errors 1`] = `Array []`;
exports[`loader should work and output the "compressed" outputStyle when "mode" is production (dart-sass) (sass): warnings 1`] = `Array []`;
exports[`loader should work and output the "compressed" outputStyle when "mode" is production (dart-sass) (scss): errors 1`] = `Array []`;
exports[`loader should work and output the "compressed" outputStyle when "mode" is production (dart-sass) (scss): warnings 1`] = `Array []`;
exports[`loader should work and output the "compressed" outputStyle when "mode" is production (node-sass) (sass): errors 1`] = `Array []`;
exports[`loader should work and output the "compressed" outputStyle when "mode" is production (node-sass) (sass): warnings 1`] = `Array []`;
exports[`loader should work and output the "compressed" outputStyle when "mode" is production (node-sass) (scss): errors 1`] = `Array []`;
exports[`loader should work and output the "compressed" outputStyle when "mode" is production (node-sass) (scss): warnings 1`] = `Array []`;
exports[`loader should work and use the "_index" file in package (dart-sass) (sass): errors 1`] = `Array []`;
exports[`loader should work and use the "_index" file in package (dart-sass) (sass): warnings 1`] = `Array []`;
Expand Down
1 change: 1 addition & 0 deletions test/helpers/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export default function(fixture, config = {}, options = {}) {
plugins: plugins(config),
optimization: {
runtimeChunk: false,
minimizer: [],
},
// eslint-disable-next-line no-undefined
resolve: config.resolve || undefined,
Expand Down
23 changes: 23 additions & 0 deletions test/loader.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,29 @@ describe('loader', () => {
expect(stats.compilation.warnings).toMatchSnapshot('warnings');
expect(stats.compilation.errors).toMatchSnapshot('errors');
});

it(`should work and output the "compressed" outputStyle when "mode" is production (${implementationName}) (${syntax})`, async () => {
const testId = getTestId('language', syntax);
const options = {
implementation: getImplementationByName(implementationName),
};
const stats = await compile(testId, {
mode: 'production',
loader: { options },
});

expect(getCode(stats).content).toBe(
getPureCode(
testId,
Object.assign({}, options, {
outputStyle: 'compressed',
})
)
);

expect(stats.compilation.warnings).toMatchSnapshot('warnings');
expect(stats.compilation.errors).toMatchSnapshot('errors');
});
});
});
});

0 comments on commit b2af379

Please sign in to comment.