css-modules-typescript-loader icon indicating copy to clipboard operation
css-modules-typescript-loader copied to clipboard

feat: Support named exports

Open laverdet opened this issue 2 years ago • 2 comments

BREAKING CHANGE: Updates the declaration template.

This is a followup on #38

The exports = declaration was added in e7342df507 but removed in 908d49159d due some issue in babel which I can't reproduce. Maybe that has been fixed downstream in the meantime.

Due to microsoft/TypeScript#40594 we cannot export these names directly since class names might not be valid JavaScript identifiers, even though they are valid exported names. When that TypeScript bug is resolved this can be changed to export the names directly instead of using export =. The problem with export = is that it will let you do import * as css from ... in addition to import css from ... even though only import * will work.


When the TypeScript bug is resolved this output should be converted to use named exports instead of exports =

Named exports resolve the Terser bailout condition described in webpack/webpack#17626 but reduce "grepability" of your code.

laverdet avatar Oct 24 '23 20:10 laverdet

This is part of a series of pull requests which adds better ecosystem support for exporting original, non-mangled, CSS names as named exports.

webpack-contrib/css-loader#1549 webpack-contrib/mini-css-extract-plugin#1057 seek-oss/css-modules-typescript-loader#50

Due to the optimization bailout condition [webpack/webpack#17626] with JSON default exports consumed by hoistable functions, original non-minified CSS module class names can be found in the minified source code.

laverdet avatar Oct 24 '23 20:10 laverdet