diff --git a/.changeset/gold-pumas-invite.md b/.changeset/gold-pumas-invite.md new file mode 100644 index 000000000..9aa030568 --- /dev/null +++ b/.changeset/gold-pumas-invite.md @@ -0,0 +1,5 @@ +--- +'preact-cli': patch +--- + +Fixes bug with style loader that would strip non-module CSS files if 'sideEffects' was set to false for the package. diff --git a/packages/cli/lib/lib/webpack/webpack-base-config.js b/packages/cli/lib/lib/webpack/webpack-base-config.js index 1b6923ffb..4cda50a71 100644 --- a/packages/cli/lib/lib/webpack/webpack-base-config.js +++ b/packages/cli/lib/lib/webpack/webpack-base-config.js @@ -269,6 +269,11 @@ module.exports = function (env) { }, }, ], + // Don't consider CSS imports dead code even if the + // containing package claims to have no side effects. + // Remove this when webpack adds a warning or an error for this. + // See https://github.com/webpack/webpack/issues/6571 + sideEffects: true, }, { test: /\.(xml|html|txt|md)$/, diff --git a/packages/cli/tests/build.test.js b/packages/cli/tests/build.test.js index 65b4ddb12..ee30b2f79 100644 --- a/packages/cli/tests/build.test.js +++ b/packages/cli/tests/build.test.js @@ -208,6 +208,16 @@ describe('preact build', () => { expect(() => build(dir)).not.toThrow(); }); + it('should import non-modules CSS even when side effects are false', async () => { + let dir = await subject('side-effect-css'); + await build(dir); + + let head = await getHead(dir); + expect(head).toEqual( + expect.stringMatching(getRegExpFromMarkup(images.sideEffectCss)) + ); + }); + it('should copy resources from static to build directory', async () => { let dir = await subject('static-root'); await build(dir); diff --git a/packages/cli/tests/images/build.js b/packages/cli/tests/images/build.js index 0d6f311f7..16affa9a1 100644 --- a/packages/cli/tests/images/build.js +++ b/packages/cli/tests/images/build.js @@ -55,6 +55,23 @@ exports.sass = `
`; +exports.sideEffectCss = ` +
+ +