webpack / webpack

A bundler for javascript and friends. Packs many modules into a few bundled assets. Code Splitting allows for loading parts of the application on demand. Through "loaders", modules can be CommonJs, AMD, ES6 modules, CSS, Images, JSON, Coffeescript, LESS, ... and your custom stuff.
https://webpack.js.org
MIT License
64.55k stars 8.78k forks source link

Native CSS support #14893

Open sokra opened 2 years ago

sokra commented 2 years ago

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

Explainer (not everything is implemented yet):

Implemented:

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

webpack-bot commented 2 years ago

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.

alexander-akait commented 2 years ago

bump

webpack-bot commented 2 years ago

Issue was closed because of inactivity.

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

alexander-akait commented 1 year ago

/cc @TheLarkInn We have this, so I just will add more things from css-loader/etc so we can see our progress

alexander-akait commented 1 year ago

Broken URL - https://github.com/webpack/webpack/issues/16969#issue-1664483188

hardfist commented 1 year ago

@alexander-akait I'm wondering how experiments.css working with the current css-loader ecosystem,for example https://github.com/seek-oss/css-modules-typescript-loader which consume the result of css-loader, but since experiments.css handle css after loader there're no chances for other loader to get css-module intermediate result, will experiments.css expose some hooks for this scenarios?

alexander-akait commented 1 year ago

@alexander-akait I'm wondering how experiments.css working with the current css-loader ecosystem,for example https://github.com/seek-oss/css-modules-typescript-loader which consume the result of css-loader, but since experiments.css handle css after loader there're no chances for other loader to get css-module intermediate result, will experiments.css expose some hooks for this scenarios?

It doesn't work, css-loader and etc output a warning and do nothing. Anyway you can set type: ""javascript/auto" and css-loader will work as before.

css-modules-typescript-loader should be rewritten, it should be a plugin which takes CSS dependecies and modify generated code, it is no hard to implement, we can't adopt it and make compatibility, because css-modules-typescript-loader uses generated JS by css-loader, I don't know why it was implemented in such way, because it should be just an option for css-loader (just a custom function that postprocess exports).

alexander-akait commented 1 year ago

The main idea of the new CSS pipeline - avoid generate JS and CSS multiple times, like we have right now

hardfist commented 1 year ago

i do agree this should be implemented as plugin and no need to be compatible,how this plugin should be implemented becomes a problem,should this plugin consume css dep directly and do the same codegen logic as internal css codegen or should it just consume the intermediate result of intetnal css module processing

alexander-akait commented 1 year ago

@hardfist

i do agree this should be implemented as plugin and no need to be compatible,how this plugin should be implemented becomes a problem,should this plugin consume css dep directly and do the same codegen logic as internal css codegen or should it just consume the intermediate result of intetnal css module processing

Yeah, we need to think about it, maybe we can introduce extra hooks to simplify this process, let's keep this here, We wanted to finish normal CSS support firslty and then I will think about it and put in our test cases a simplified example

hardfist commented 1 year ago

I'm not sure whether all the options in css-loader and mini-css-extract-plugin will be supported in experiments.css, and we're migrating some applications from css-loader & mini-css-extract-plugin to experiments.css and missing some functionalities, so maybe I can track these in this issue or file separate issue?

if these functionalities are accepted we're willing to implement it for webpack

fregante commented 1 year ago

from https://github.com/webpack/webpack/issues/17700

It's unclear how to get the old extract + css-loader setup: generate CSS files and do nothing else.

Currently it appears that experiments.css: true generates the CSS files but also tries to load them, causing this error in my environment (web extension)

Uncaught TypeError: Failed to execute 'getComputedStyle' on 'Window': parameter 1 is not of type 'Element'.
    at loadCssChunkData (refined-github.js:28644:21)

Which wasn't the case with the following configuration:

module: {
    rules: [
        {
            test: /\.css$/,
            use: [
                MiniCssExtractPlugin.loader,
                'css-loader',
            ],
        },
    ]
},
plugins: [
    new MiniCssExtractPlugin(),
],
jeromehan commented 1 year ago

getComputedStyle

@fregante This might help you https://github.com/webpack/webpack/issues/16147#issuecomment-1583612714

fregante commented 1 year ago

No, webpack should not run any JavaScript if I ask it to generate a CSS file, so that isn't useful for this scenario.

Sushil642 commented 6 months ago

Dear @sokra ,

I am Sushil SIngh. I'm writing to express my interest in contributing to the ongoing enhancement of Webpack's CSS capabilities, specifically Issue #14893 . I have reviewed the provided information and believe that I possess the necessary skills to make meaningful contributions to the project.

francescocaveglia commented 3 weeks ago

Hi,

there is any way to opt-out from the css variables rewrite and use localIdentName only for css classes?

Another thing, is possible to ignore the url()s, like with the url option of css-loader?

alexander-akait commented 3 weeks ago

@francescocaveglia

there is any way to opt-out from the css variables rewrite and use localIdentName only for css classes?

can you provide why you need disable it?

Another thing, is possible to ignore the url()s, like with the url option of css-loader?

https://webpack.js.org/plugins/ignore-plugin/

francescocaveglia commented 3 weeks ago

Hi @alexander-akait

can you provide why you need disable it?

In our project we use an external web components library and we have many customizations made through CSS variables. Having them rewritten means we should wrap every instance with :global

https://webpack.js.org/plugins/ignore-plugin/

It is possible to configure it to ignore "every resource inside a url() call"?

Thanks

alexander-akait commented 3 weeks ago

In our project we use an external web components library and we have many customizations made through CSS variables. Having them rewritten means we should wrap every instance with :global

Do you have :local? We can make it an option for this

It is possible to configure it to ignore "every resource inside a url() call"?

You can use this as function, what setup do you have for css-loader?

fregante commented 3 weeks ago

Could this support request be moved out of here? It’s off topic, I’m following the issue to get updates about native CSS support