-
-
Notifications
You must be signed in to change notification settings - Fork 611
docs: clarify behavior of importing CSS from JavaScript #1655
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
d622278
4220ff9
0e2e2c3
8822772
676801b
25609d1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -47,7 +47,17 @@ Then, add the loader to your `webpack` configuration. For example: | |
| **file.js** | ||
|
|
||
| ```js | ||
| import * as css from "file.css"; | ||
| import * as css from "./file.css"; | ||
| ``` | ||
|
|
||
| When using `css-loader`, importing a CSS file from JavaScript works because webpack processes the file through the loader pipeline and turns it into a JavaScript module. | ||
|
|
||
| The imported value is not a native `CSSStyleSheet`. Instead, it is a JavaScript module generated by `css-loader`. When CSS Modules are enabled, the import can contain exported identifiers (such as class name mappings) from the CSS file. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In some cases yes, so it is wrong |
||
|
|
||
| If you only want to apply the styles and do not need to access any exports, you can simply write: | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this doesnt reference anything
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. updated to reference imported module clearly |
||
|
|
||
| ```js | ||
| import "./file.css"; | ||
|
evenstensberg marked this conversation as resolved.
|
||
| ``` | ||
|
|
||
| **webpack.config.js** | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove pipeline, and link to our docs page where loaders are documented.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done