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

Class names that are not valid JS identifiers are excluded from Webpack bundle #294

Closed
kevinkace opened this issue May 8, 2017 · 8 comments

Comments

@kevinkace
Copy link
Contributor

CSS class names are exported differently in a webpack bundle depending if the class names are valid JS identifiers or not. Invalid class names are only included under .default.

.thing {
  display: block;
}
.thing-0 {
  display: block;
}
(function(module, __webpack_exports__, __webpack_require__) {

"use strict";
Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "thing", function() { return thing; });
var thing = "mc7c4fa8d1_thing";
/* harmony default export */ __webpack_exports__["default"] = ({
    "thing": "mc7c4fa8d1_thing",
    "thing-1": "mc7c4fa8d1_thing-1"
});

}),

Test repo: https://github.com/kevinkace/webpackTest

@tivac
Copy link
Owner

tivac commented May 8, 2017

This came about because of the change to ES2015 exports in #282, seems like it's related to webpack/webpack#4742

@tivac
Copy link
Owner

tivac commented May 8, 2017

I may need to revert the change to use ES2015 exports, will see which API is more annoying. Having to require("./file.css").default to get at all the exports when using - in selector names is not-great.

/cc @TrySound as the source of the request for ES2015 exports to hear another perspective.

@TrySound
Copy link
Contributor

TrySound commented May 9, 2017

@kevinkace Using require().default is normal as es modules is standard which should be used all the time. Of course with es modules you don't need to access default explicitly, just import style from './style.css'; or better import * as style from './style.css';.

Maybe this should be a breaking change, but this is the right way.

@TrySound
Copy link
Contributor

TrySound commented May 9, 2017

@tivac Not a bug. Just two different module systems.

@TrySound
Copy link
Contributor

TrySound commented May 9, 2017

Webpack guys force to use es modules and rewrites loaders with them, so why should we step back?

@tivac
Copy link
Owner

tivac commented May 9, 2017

Current plan is to add a cjs option to webpack plugin. When truthy the output will be commonjs-style module.exports instead of ES2015 modules.

Hoping to get this work completed tonight.

There are plenty of legitimate reasons to still use commonjs, so it needs to be supported in a reasonable & compatible way.

@TrySound
Copy link
Contributor

Yeah, it's good, but disabled by default :)

@tivac
Copy link
Owner

tivac commented May 10, 2017

This is in modular-css-webpack@4.4.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants