Skip to content

[wip] webpack5 ng css - #9434

Merged
rigor789 merged 3 commits into
feat/webpack5from
feat/webpack-ng-css
Aug 3, 2021
Merged

rigor789 merged 3 commits into
feat/webpack5from
feat/webpack-ng-css

Conversation

@rigor789

@rigor789 rigor789 commented Jun 2, 2021 •

Copy link
Copy Markdown
Member

@cla-bot cla-bot Bot added the cla: yes label Jun 2, 2021
@rigor789
rigor789 changed the base branch from master to feat/webpack5 June 2, 2021 17:27
@edusperoni

Copy link
Copy Markdown
Contributor

Nice!

But I think this might match app.component.css as the base css rule. I'm not sure how we could limit it to only appPath/app(.platform)?.css . Also would be interesting to see how we treat external css from node_modules. Angular inlines css in the libraries, so I think most external .css files are safely assumed to be core related.

I think the "correct" config my be:
css rule: appPath/app(.platform)?.css and node_modules/**/*.css
angular rule: appPath/**/*.css excluding appPath/app(.platform)?.css.

On one of my projects I did this, but it might be a bit dirty:

        config.module
            .rule('scss')
            .include
            .add(path.join(webpack.Utils.platform.getEntryDirPath(), 'app.scss'))
            .add(path.join(webpack.Utils.platform.getEntryDirPath(), 'app.android.scss'))
            .add(path.join(webpack.Utils.platform.getEntryDirPath(), 'app.ios.scss'));
        config.module
            .rule('scss|component')
            .test(/\.scss$/)
            .exclude
            .add(path.join(webpack.Utils.platform.getEntryDirPath(), 'app.scss'))
            .add(path.join(webpack.Utils.platform.getEntryDirPath(), 'app.android.scss'))
            .add(path.join(webpack.Utils.platform.getEntryDirPath(), 'app.ios.scss'));

might need another include for node_modules on the scss rule? I'm not sure how prevalent that is. Preferably the libraries should provide an entrypoint for css so that isn't needed.

.rule('css')
.include.add(resolve(getEntryDirPath(), 'app.css'))
.add(resolve(getEntryDirPath(), `app.${platform}.css`))
.add(/node_modules/);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@edusperoni This would I believe include all files in node_modules, since there's no extension checking.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rigor789 doesn't it extend from the base rule which does test for the extension?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah you are right, for some reason I thought we had deleted the base rule.

@edusperoni

Copy link
Copy Markdown
Contributor

@rigor789 how about my latest commit?

Still have to test all scenarios out, but basically:

scss/css rules will match:
src/app.css,src/app.platform.css, node_modules

scss/css|component rules will match:
everything but the above.

If a developer wants to load a css file normally (import './pathTo.scss';), they have to do:

config.rule('scss').include.add(pathToCssFile);
config.rule('scss|component').exclude.add(pathToCssFile);

If they want to match a scss file somewhere else, they have to swap scss and `scss|component´ in the code above.

Considering Angular devs never import css manually, this should cover all bases.

Thoughts?

@rigor789

Copy link
Copy Markdown
Member Author

@edusperoni lgtm, though I would like to give this a spin in an app and see if everything works as expected.

Could you run the tests & update the snapshots? (npm run test --watch and then press u once the tests fail to update the snapshots)

@edusperoni

Copy link
Copy Markdown
Contributor

I think this is should be ready for merge

@edusperoni
edusperoni marked this pull request as ready for review July 23, 2021 18:42
@rigor789
rigor789 merged commit cb91cd8 into feat/webpack5 Aug 3, 2021
@rigor789
rigor789 deleted the feat/webpack-ng-css branch August 3, 2021 12:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants