question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Question]Will Webpack support CSS module scripts?

See original GitHub issue

It seems that Chrome implements CSS module scripts which imports CSS using import assertion. https://web.dev/css-module-scripts/

import sheet from './styles.css' assert { type: 'css' };
document.adoptedStyleSheets = [sheet];
shadowRoot.adoptedStyleSheets = [sheet];

This seems to have different specifications than when using css-loader. I’m wondering if I need to be aware of the difference between css-loader and CSS module scripts in the future.

// CSS module scripts
import sheet from './styles.css' assert { type: 'css' };
// with css-loader
import sheet from './styles.css';

Are there any plans to support this on the Webpack side? Is this a problem that another library should address?

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:2
  • Comments:17 (13 by maintainers)

github_iconTop GitHub Comments

2reactions
alexander-akaitcommented, Nov 15, 2021

@AkifumiSato Not fully finished

2reactions
sokracommented, Aug 30, 2021

assert handling is already in the core. You can do that:

module.rules: [ {
  test: /\.css$/,
  oneOf: [
    { assert: { type: "css" }, loader: "css-loader", options: { exportStylesheet: true } },
    { loader: "css-loader", options: { exportStylesheet: false } }
  ]
} ]

Assuming css-loader supports exportStylesheet, which it currently don’t

Read more comments on GitHub >

github_iconTop Results From Across the Web

css-loader | webpack - JS.ORG
webpack is a module bundler. Its main purpose is to bundle JavaScript files for usage in a browser, yet it is also capable...
Read more >
How to configure CSS Modules for webpack - LogRocket Blog
Increase the flexibility of your app's CSS components with CSS Modules and Webpack in this handy tutorial and demo app build.
Read more >
似て非なるCSS Module Scripts - Zenn
[Question]Will Webpack support CSS module scripts? · Issue #14063 · webpack/webpack. It seems that Chrome implements CSS module scripts ...
Read more >
How to configure CSS and CSS modules in webpack
Before we configure CSS support in the webpack setup, let's first add a CSS file and use it. The first thing we are...
Read more >
How to use CSS Modules with TypeScript and webpack
Using CSS Modules with TypeScript is not as obvious as with JavaScript. There are several ways to do that.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found