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: respect the compress option #303

Merged
merged 1 commit into from Jan 15, 2021
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
5 changes: 4 additions & 1 deletion src/utils.js
Expand Up @@ -34,7 +34,10 @@ function getStylusOptions(loaderContext, loaderOptions) {
? stylusOptions.resolveURL
: { nocheck: true };

if (!stylusOptions.compress && isProductionLikeMode(loaderContext)) {
if (
typeof stylusOptions.compress === "undefined" &&
isProductionLikeMode(loaderContext)
) {
stylusOptions.compress = true;
}

Expand Down
22 changes: 22 additions & 0 deletions test/__snapshots__/loader.test.js.snap
Expand Up @@ -917,6 +917,28 @@ exports[`loader should work "use" option: errors 1`] = `Array []`;

exports[`loader should work "use" option: warnings 1`] = `Array []`;

exports[`loader should work and respect the "compress" option with the "false" value: css 1`] = `
"body {
font: 12px Helvetica, Arial, sans-serif;
}
a.button {
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
}
"
`;

exports[`loader should work and respect the "compress" option with the "false" value: errors 1`] = `Array []`;

exports[`loader should work and respect the "compress" option with the "false" value: warnings 1`] = `Array []`;

exports[`loader should work and respect the "compress" option with the "true" value: css 1`] = `"body{font:12px Helvetica,Arial,sans-serif}a.button{-webkit-border-radius:5px;-moz-border-radius:5px;border-radius:5px}"`;

exports[`loader should work and respect the "compress" option with the "true" value: errors 1`] = `Array []`;

exports[`loader should work and respect the "compress" option with the "true" value: warnings 1`] = `Array []`;

exports[`loader should work binop import: css 1`] = `
".not-real-nib {
color: #000;
Expand Down
50 changes: 50 additions & 0 deletions test/loader.test.js
Expand Up @@ -1509,6 +1509,56 @@ describe("loader", () => {
expect(getErrors(stats)).toMatchSnapshot("errors");
});

it('should work and respect the "compress" option with the "true" value', async () => {
const testId = "./basic.styl";
const compiler = getCompiler(
testId,
{
stylusOptions: {
compress: true,
},
},
{ mode: "production" }
);
const stats = await compile(compiler);
const codeFromBundle = getCodeFromBundle(stats, compiler);
const codeFromStylus = await getCodeFromStylus(testId, {
stylusOptions: {
compress: true,
},
});

expect(codeFromBundle.css).toBe(codeFromStylus.css);
expect(codeFromBundle.css).toMatchSnapshot("css");
expect(getWarnings(stats)).toMatchSnapshot("warnings");
expect(getErrors(stats)).toMatchSnapshot("errors");
});

it('should work and respect the "compress" option with the "false" value', async () => {
const testId = "./basic.styl";
const compiler = getCompiler(
testId,
{
stylusOptions: {
compress: false,
},
},
{ mode: "production" }
);
const stats = await compile(compiler);
const codeFromBundle = getCodeFromBundle(stats, compiler);
const codeFromStylus = await getCodeFromStylus(testId, {
stylusOptions: {
compress: false,
},
});

expect(codeFromBundle.css).toBe(codeFromStylus.css);
expect(codeFromBundle.css).toMatchSnapshot("css");
expect(getWarnings(stats)).toMatchSnapshot("warnings");
expect(getErrors(stats)).toMatchSnapshot("errors");
});

it("should use .json file", async () => {
const testId = "./json/index.styl";
const compiler = getCompiler(testId, {
Expand Down