diff --git a/src/utils.js b/src/utils.js index 0b2e9a5..c2eff88 100644 --- a/src/utils.js +++ b/src/utils.js @@ -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; } diff --git a/test/__snapshots__/loader.test.js.snap b/test/__snapshots__/loader.test.js.snap index a789355..cc91396 100644 --- a/test/__snapshots__/loader.test.js.snap +++ b/test/__snapshots__/loader.test.js.snap @@ -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; diff --git a/test/loader.test.js b/test/loader.test.js index c9f82f2..ad62efc 100644 --- a/test/loader.test.js +++ b/test/loader.test.js @@ -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, {