GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Native CSS support · Issue #14893 · webpack/webpack

Native CSS support #14893

New issue
Copy link
New issue
Copy link
Closed
Feature
Closed
Native CSS support#14893
Feature
Copy link
Assignees
alexander-akait

Description

@sokra
sokra
opened on Dec 2, 2021
Issue body actions

Current State: opt-in via experiments.css: true

Explainer (not everything is implemented yet):

  • experiments.css: true enables the native css support in webpack
  • This will be enabled by default in webpack 6
  • There will be multiple modes depending on how you reference CSS
    • A: import "./style.css": Attaches the stylesheet to the document as side effect of importing. @import and url() are resolved.
    • B: import stylesheet from "./style.css" asset { type: "css" }: Exports the unattached stylesheet as default export. You can adopt it according to the spec. @import is not allowed (yet), but url() will be resolved.
    • C: import { main } from "./style.module.css": Like A, but renames all css classes, keyframes and css variables and exports the new names. @import and url() are resolved.
    • D: new URL("./style.css", import.meta.url): Gives an URL to a stylesheet including all styles. @import and url() are resolved.
    • E: import { main } from "./style.module.css": Like C, but for the node.js target. It generates a JSON module with the exports from the CSS.
  • A and C will bundle all CSS of a chunk into a single CSS file (per chunk)
  • splitChunks will allow to move CSS around
  • output.cssFilename and output.cssChunkFilename allows to configure the filename template for css files. By default it copies filename resp. chunkFilename with extension changed to .css
  • HMR will update CSS when you edit it.
  • There is external CSS that will lead to @import "..." in the output css files
  • There are external assets that will lead to a external url.
  • class names are based on module ids, so you need to make sure that SSR and Client module ids match
    • E1: Compute module ids in a deterministic way -> DeterministicModuleIdsPlugin
    • E2: Store module ids in a file and load them on the other side -> SyncModuleIdsPlugin
  • In addition to the default bindings, you can use type: "css/..." in rules to apply loader results as css. e. g. for Sass support.
  • This will replace mini-css-extract-plugin and css-loader
  • It will be more performant, by using a css tokenizer instead of postcss
  • There is a css minimizer in production mode.

Implemented:

  • A
  • @import url("...");
  • @import "...";
  • url()
  • chunking
  • on demand loading
  • HMR
  • splitChunks
  • output.cssFilename
  • external type css-import
  • external type asset
  • :export blocks
  • correct css order in output file
  • warnings for ordering issues
  • E
  • E1
  • E2
  • image-set()
  • @import url("...") layer(test);
  • @import url("...") supports(...);
  • @import url("...") media query;
  • move all external imports to top
  • do not ignore #import and make them external
  • inherit layer, supports(...) and media from parent module
  • supports style resolution in package.json and test it + test support loader usage
  • Implement CSS Module fetchpriority
  • prefetch/preload for CSS
  • external import with media/supports
  • Correct publicPath for assets modules inside CSS files
  • pathinfo for @import
  • prefeth/preload only for CSS import() generates prefetch/preload runtime for JS
  • default type: css enables CSS modules support (i.e. for CSS without CSS modules you need set type: "css/global"), which might be a bit confusing for developers, because some developer just want to use pure CSS and parsing CSS modules can affect on perf, I think we should do:
    • type: "css/auto" - enable/disable CSS modules based on path, it is css/module or css
    • type: "css" - no CSS modules and don't try to parse CSS modules things
    • type: "css/module" - CSS modules with local mode
    • type: "css/global" CSS modules with global mode
  • rewrite to be align with CSS spec
  • src()
  • unstable ?hash generation in --webpack-main when you have multiple same modules
  • improve logic in callback (more perfomance?) + better error reporting for @import
  • implement /* webpackIgnore: true */ for url()/image-set()
  • url() in css leaves an asset JS Module in js chunk
  • :import blocks
  • @value
  • Experiments.css reliance on fact that css should be loaded before js is a huge breaking change #17611 - allow link be before/after script + bug with safari
  • support legacy browser? experimental.css not support legacy browser? #16147
  • CSS entry without JS file (option to do only extract without runtime + for dynamic?) and hmr
  • C
  • move tests frompostcss-modules-* packages
  • B
  • local() and global() in declarations
  • re-export for :export/@value/var()/classes and nested @import + internal refactor CSS parser (ICSS inheritance)
  • improve hashing of locals for production + no extra _ at start
  • url("font.svg#svgFontName") created invalid filename
  • css/global align with spec + local()/global()
  • more at-rules rename and grid + @function + options in css modules
  • remove empty async chunks + improve concatenation for CSS modules
  • move tests from css-loader
  • contenthashing and hash for CSS files (hashUpdate)
  • move test from extract plugin
  • pure mode
  • D [WIP]

Not implemented/tested, but Planned (ordered by priority):

  • css minimizer enable by default
Reacted by nyngwang, Furkan Erdem, MuneebStack, Soon, Arjun, Axetroy, Jon Dufresne and hai-x
Reacted by Sammy Marsden, Zach Wegrzyniak, fregante, Nick Chevsky, Marsel Shaikhin, Moneko, nyngwang, MuneebStack, Arjun, Aliaksandr Radzivanovich and 4 more

Activity

Next
  1. webpack
    locked as resolved and limited conversation to collaborators on Dec 2, 2021
  2. webpack-bot commented on Mar 4, 2022

    @webpack-bot
    webpack-bot
    on Mar 4, 2022
    Contributor
    More actions

    This issue had no activity for at least three months.

    It's subject to automatic issue closing if there is no activity in the next 15 days.

  3. webpack-bot
    added
    status: staleNo author response after a needs: request; close candidate
    on Mar 4, 2022
  4. alexander-akait commented on Mar 4, 2022

    @alexander-akait
    alexander-akait
    on Mar 4, 2022
    Member
    More actions

    bump

  5. webpack-bot
    removed
    status: staleNo author response after a needs: request; close candidate
    on Mar 4, 2022
  6. webpack-bot
    added
    status: staleNo author response after a needs: request; close candidate
    on Jun 4, 2022
  7. webpack-bot
    closed this as completedon Jun 19, 2022
  8. webpack-bot commented on Jun 19, 2022

    @webpack-bot
    webpack-bot
    on Jun 19, 2022
    Contributor
    More actions

    Issue was closed because of inactivity.

    If you think this is still a valid issue, please file a new issue with additional information.

  9. alexander-akait
    reopened this on Jun 19, 2022
  10. webpack-bot
    removed
    status: staleNo author response after a needs: request; close candidate
    on Jun 19, 2022
  11. webpack-bot
    added
    status: staleNo author response after a needs: request; close candidate
    on Sep 18, 2022
  12. webpack-bot
    closed this as completedon Oct 4, 2022
  13. alexander-akait
    reopened this on Oct 6, 2022
  14. webpack-bot
    removed
    status: staleNo author response after a needs: request; close candidate
    on Oct 6, 2022
  15. webpack-bot
    added
    status: staleNo author response after a needs: request; close candidate
    on Jan 6, 2023
  16. 27 remaining items

  17. webpack-bot
    closed this as completedon Mar 1, 2025
  18. alexander-akait
    reopened this on Mar 3, 2025
  19. alexander-akait
    removed
    status: staleNo author response after a needs: request; close candidate
    on Nov 6, 2025
  20. alexander-akait
    added the
    Feature
    issue type on Nov 6, 2025
  21. alexander-akait
    self-assigned this
    on Dec 15, 2025
  22. intellild commented on Jun 18, 2026

    @intellild
    intellild
    on Jun 18, 2026
    Contributor
    More actions

    I’m a bit concerned about the broader implications of treating new URL("style.css", import.meta.url) as a bundled CSS dependency instead of a copied asset. If CSS receives this special handling, should similar references like new URL("./script.ts", import.meta.url) also become bundled entry/dependency references in the future, rather than asset URLs? I’m also wondering how this behavior should relate to require.resolve, and eventually import.meta.resolve, since all of these APIs can be used to obtain resolved resource URLs or paths. It would be helpful to clarify where webpack draws the line between “resolve to an asset URL” and “include this file in the module graph and process it according to its type,” so users can rely on consistent behavior going forward.

    Reacted by fregante
  23. alexander-akait commented on Jun 18, 2026

    @alexander-akait
    alexander-akait
    on Jun 18, 2026
    Member
    More actions

    If CSS receives this special handling, should similar references like new URL("./script.ts", import.meta.url) also become bundled entry/dependency references in the future, rather than asset URLs?

    Yes, we want to do it, for HTML too

    It would be helpful to clarify where webpack draws the line between “resolve to an asset URL” and “include this file in the module graph and process it according to its type,” so users can rely on consistent behavior going forward.

    Good question, we are still think about it, should be do it by default or provide an option(s) for parsers to enable it or not, also maybe we will implement special webpack comments to control it inside code, regarding URL construction - we make it only when we can resolve URL, if we can't we keep code as is

    We are open to feedback about default behavior

    Maybe you can provide cases where you don't want to include modules in the graph using new URL?

  24. intellild commented on Jun 18, 2026

    @intellild
    intellild
    on Jun 18, 2026
    Contributor
    More actions

    If CSS receives this special handling, should similar references like new URL("./script.ts", import.meta.url) also become bundled entry/dependency references in the future, rather than asset URLs?

    Yes, we want to do it, for HTML too

    It would be helpful to clarify where webpack draws the line between “resolve to an asset URL” and “include this file in the module graph and process it according to its type,” so users can rely on consistent behavior going forward.

    Good question, we are still think about it, should be do it by default or provide an option(s) for parsers to enable it or not, also maybe we will implement special webpack comments to control it inside code, regarding URL construction - we make it only when we can resolve URL, if we can't we keep code as is

    We are open to feedback about default behavior

    Maybe you can provide cases where you don't want to include modules in the graph using new URL?

    I don’t currently have a concrete use case for excluding modules from the graph when using new URL.

    I do have some examples where I’d like the modules to be included in the graph, such as https://github.com/intellild/resolve-examples . That said, I’m not sure whether new URL is the best fit here, or whether we should consider alternatives like require.resolve or import.meta.resolve.

    The challenge is that users may expect require.resolve("./foo.ts") to be transformed into require.resolve("./foo.js"), allowing the actual path to be resolved at runtime.

  25. intellild commented on Jun 18, 2026

    @intellild
    intellild
    on Jun 18, 2026
    Contributor
    More actions

    I think assets can be handled through module rules, so that part may not be an issue.

    The main question now is whether we should use new URL, require.resolve, or import.meta.resolve.

  26. alexander-akait commented on Jun 18, 2026

    @alexander-akait
    alexander-akait
    on Jun 18, 2026
    Member
    More actions

    We don't touch import.meta.resolve, in future we should allow to bundle it, but by default it will be false, only when I set it to true for module or global for all modules, new URL is resolving and including in graph only when we can really resolve it, otherwise it will be as is in code, require.resolve - we handle it by default due historical reasons

  27. intellild commented on Jun 18, 2026

    @intellild
    intellild
    on Jun 18, 2026
    Contributor
    More actions

    🤔 Maybe we can just keep the relative path in the output, new URL("./script.ts", import.meta.url) becomes new URL("./output-chunk.js", import.meta.url).

    Then in browser or node, it is resolved to real url path.
    For lib authors, it can still be consumed by downstream bundlers.

  28. alexander-akait commented on Jun 19, 2026

    @alexander-akait
    alexander-akait
    on Jun 19, 2026
    Member
    More actions

    @intellild generation of analyzable ECMA modules output is included in our plans for the next minor release

    Reacted by AsyncIter
  29. nathanielprice713-coder commented on Jul 1, 2026

    @nathanielprice713-coder
    nathanielprice713-coder
    on Jul 1, 2026 via email
    More actions
    That’s great news about the plans for the next minor release. Having analyzable ECMA modules in the output will definitely help with consistency and downstream bundling. I'll look forward to seeing how the implementation for native CSS and HTML progress.
    …
    On Fri, Jun 19, 2026, 10:38 AM Alexander Akait ***@***.***> wrote: *alexander-akait* left a comment (webpack/webpack#14893) <#14893 (comment)> @intellild <https://github.com/intellild> generation of analyzable ECMA modules output is included in our plans for the next minor release — Reply to this email directly, view it on GitHub <#14893?email_source=notifications&email_token=CC24FTNNBCPJA7TWCLIBEM35AVF53A5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTINZVGI2DOOJYG4ZKM4TFMFZW63VKON2WE43DOJUWEZLEUVSXMZLOOSWGM33PORSXEX3DNRUWG2Y#issuecomment-4752479872>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/CC24FTOGTOVFZPZX5CWMWB35AVF53AVCNFSNUABDKJSXA33TNF2G64TZHMZTMNZYG4ZTCO2JONZXKZJ3GEYDMOJZGQ2DSMZRUF3AE> . Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS <https://github.com/notifications/mobile/ios/CC24FTPHM5XHO3VSJ72ZAXT5AVF53A5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTINZVGI2DOOJYG4ZKM4TFMFZW63VKON2WE43DOJUWEZLEUVSXMZLOOSVGM33PORSXEX3JN5ZQ> and Android <https://github.com/notifications/mobile/android/CC24FTIVJGQCYD2F2NG6KXT5AVF53A5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTINZVGI2DOOJYG4ZKM4TFMFZW63VKON2WE43DOJUWEZLEUVSXMZLOOSXGM33PORSXEX3BNZSHE33JMQ>. Download it today! You are receiving this because you are subscribed to this thread.Message ID: ***@***.***>
  30. alexander-akait commented on Jul 31, 2026

    @alexander-akait
    alexander-akait
    on Jul 31, 2026
    Member
    More actions

    We can close it, css supported ship, only couple features left - more safe optimizations for css and html, new URL resolving, but we have PRs for them and they still need to be discussed

    Reacted by hai-x
    Reacted by hai-x
  31. alexander-akait
    closed this as completedon Jul 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @alexander-akait
    alexander-akait

Labels

No labels
No labels

Type

Feature

Fields

Priority

None yet

Start date

None yet

Target date

None yet

Effort

None yet

Projects

    • webpack 5/6
      Closed
      Status
      Priority - High
      Show more project fields

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402775 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.