Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use "compressed" output when mode is "production" #723

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/getSassOptions.js
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
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
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
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');
});
});
});
});