Title: Prefixable style imports similar to tsconfig.json's compilerOptions.paths · Issue #12573 · angular/angular-cli · GitHub
Open Graph Title: Prefixable style imports similar to tsconfig.json's compilerOptions.paths · Issue #12573 · angular/angular-cli
X Title: Prefixable style imports similar to tsconfig.json's compilerOptions.paths · Issue #12573 · angular/angular-cli
Description: Bug Report or Feature Request (mark with an x) - [ ] bug report -> please search issues before submitting - [x] feature request Command (mark with an x) - [ ] new - [] build - [] serve - [] test - [ ] e2e - [ ] generate - [ ] add - [ ] u...
Open Graph Description: Bug Report or Feature Request (mark with an x) - [ ] bug report -> please search issues before submitting - [x] feature request Command (mark with an x) - [ ] new - [] build - [] serve - [] test - ...
X Description: Bug Report or Feature Request (mark with an x) - [ ] bug report -> please search issues before submitting - [x] feature request Command (mark with an x) - [ ] new - [] build - [] serve - [] test...
Opengraph URL: https://github.com/angular/angular-cli/issues/12573
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Prefixable style imports similar to tsconfig.json's compilerOptions.paths","articleBody":"### Bug Report or Feature Request (mark with an `x`)\r\n```\r\n- [ ] bug report -> please search issues before submitting\r\n- [x] feature request\r\n```\r\n\r\n### Command (mark with an `x`)\r\n```\r\n- [ ] new\r\n- [] build\r\n- [] serve\r\n- [] test\r\n- [ ] e2e\r\n- [ ] generate\r\n- [ ] add\r\n- [ ] update\r\n- [ ] lint\r\n- [ ] xi18n\r\n- [ ] run\r\n- [x] config\r\n- [ ] help\r\n- [ ] version\r\n- [ ] doc\r\n```\r\n\r\n### Versions\r\n```\r\ndamien$ node --version\r\nv8.9.4\r\n-----\r\ndamien$ ng --version\r\n\r\n _ _ ____ _ ___\r\n / \\ _ __ __ _ _ _| | __ _ _ __ / ___| | |_ _|\r\n / △ \\ | '_ \\ / _` | | | | |/ _` | '__| | | | | | |\r\n / ___ \\| | | | (_| | |_| | | (_| | | | |___| |___ | |\r\n /_/ \\_\\_| |_|\\__, |\\__,_|_|\\__,_|_| \\____|_____|___|\r\n |___/\r\n \r\n\r\nAngular CLI: 6.2.3\r\nNode: 8.9.4\r\nOS: darwin x64\r\nAngular: \r\n... \r\n\r\nPackage Version\r\n------------------------------------------------------\r\n@angular-devkit/architect 0.8.3\r\n@angular-devkit/core 0.8.3\r\n@angular-devkit/schematics 0.8.3\r\n@schematics/angular 0.8.3\r\n@schematics/update 0.8.3\r\nrxjs 6.2.2\r\ntypescript 2.9.2\r\n```\r\n\r\n### Repro steps\r\n1. Add two libraries with the same scss file name: e.g `sample.scss`\r\n2. Add both libraries scss paths to your `projects.project.architect.build.stylePreprocessorOptions.includePaths`\r\n```\r\n \"build\": {\r\n \"builder\": \"@angular-devkit/build-angular:browser\",\r\n \"options\": {\r\n \"outputPath\": \"dist/apps/demo\",\r\n \"index\": \"apps/demo/src/index.html\",\r\n \"main\": \"apps/demo/src/main.ts\",\r\n \"polyfills\": \"apps/demo/src/polyfills.ts\",\r\n \"tsConfig\": \"apps/demo/tsconfig.json\",\r\n \"assets\": [\r\n \"apps/demo/src/assets\",\r\n \"apps/demo/src/favicon.ico\"\r\n ],\r\n \"styles\": [\r\n \"apps/demo/src/scss/styles.scss\"\r\n ],\r\n \"stylePreprocessorOptions\": {\r\n \"includePaths\": [\r\n \"apps/demo/src/scss\",\r\n \"libs/design/scss\"\r\n ]\r\n },\r\n \"scripts\": []\r\n }\r\n },\r\n```\r\n3. In your `src/styles.scss` reference the `sample.scss` file.\r\n```\r\n@import \"sample.scss\"\r\n```\r\n4. Be unsure which file is chosen by `sass-loader`\r\n\r\n### Desired functionality\r\n1. Add two libraries that happen to have the same scss file name: e.g `sample.scss`\r\n2. Add both libraries scss paths to your `projects.project.architect.build.stylePreprocessorOptions.includePaths` but INCLUDE a prefix if desired.\r\n```\r\n\"build\": {\r\n \"builder\": \"@angular-devkit/build-angular:browser\",\r\n \"options\": {\r\n \"outputPath\": \"dist/apps/demo\",\r\n \"index\": \"apps/demo/src/index.html\",\r\n \"main\": \"apps/demo/src/main.ts\",\r\n \"polyfills\": \"apps/demo/src/polyfills.ts\",\r\n \"tsConfig\": \"apps/demo/tsconfig.json\",\r\n \"assets\": [\r\n \"apps/demo/src/assets\",\r\n \"apps/demo/src/favicon.ico\"\r\n ],\r\n \"styles\": [\r\n \"apps/demo/src/scss/styles.scss\"\r\n ],\r\n \"stylePreprocessorOptions\": {\r\n \"includePaths\": [\r\n { path: \"apps/demo/src/scss\", prefix: \"@demo\"},\r\n { path: \"libs/design/scss\", prefix: \"@design\"},\r\n \"potentially/some/other/non-prefixed/path\"\r\n ]\r\n },\r\n \"scripts\": []\r\n }\r\n },\r\n```\r\n3. In your `src/styles.scss` reference the `sample.scss` file.\r\n```\r\n@import \"@demo/sample.scss\"\r\n@import \"@design/sample.scss\"\r\n```\r\n4. Be sure which sample was imported.\r\n\r\n### Mention any other details that might be useful\r\n\r\n#### Issues & PRs\r\nRevisits #1791\r\nRevisits #4003\r\nRevisits #5287\r\nPotential Solution for #9018\r\n\r\n#### Discussion\r\n\r\nI came about this as a part of considering how to build a [component library](https://github.com/graycoreio/daffodil) for an angular project. It struck me like a thunderbolt after reading @clydin 's commenting saying that the ideas put out by @angular/material2 with imports via `~` [are unsupported](https://github.com/angular/angular-cli/issues/11435#issuecomment-403499086)\r\n\r\nI've also spent a fair bit of time reviewing how webpack's sass-loader works compared to how the AngularCompiler plugin handles loading paths via tsconfig.json. Hats off to @clydin for the [new reliance](https://github.com/angular/angular-cli/pull/11575) on webpack.resolve for handling tsconfig.json `compilerOptions.paths` implementation in v7.0.0. Reviewing all of the PRs and issues on styles up to this point has led me to the following:\r\n\r\nI think the current includePaths functionality is severely limiting and can lead to significant confusion. It's really nice to KNOW where your styles are coming from rather than guessing which path it happens to come from. To this idea, I'd really like to point out the developer experience from component library perspective (think @angular/material2). Specifically, I'd like to clarify via a simple example of how it feels to develop components that use dependent styles (variables, mixins, functions, etc).\r\n\r\n#### Comparative Example\r\n\r\nLet's imagine we treated typescript classes & files (**critical application code**) like how `includePaths` forces us to treat `.scss/.css/.less` files (I'd also argue these are **critical application code**). \r\n\r\n```\r\nimport { Input };\r\n\r\n//as opposed to:\r\n//import { Input } from '@angular/core';\r\n```\r\n\r\nAs an application maintainer, I'd feel terrified of having any clue as to what was going on with that reference. Who knows where `Input` is coming from, which dependency you're referring to and as such, what the class even does. I can't even imagine maintaining that for a week let alone long term.\r\n\r\nCurrently, this is the experience of an Angular dev working with any kind of styles. \r\n\r\n```bash\r\n//my.component.ts\r\nimport 'util';\r\n\r\n.component {\r\n @include some-mixin-from-util;\r\n}\r\n```\r\n\r\nLooking at this, I have no idea where `util` comes from, no appreciation for whether or not it's imported from my project or a dependency and no way of knowing how to find the file. If I go check `includePaths` I'm then stuck sifting through how ever many paths are listed there. I feel that it is less than stellar and thus needs to be re-considered.\r\n\r\nIt would be much more sane to do something like:\r\n\r\n```bash\r\n//my.component.ts\r\nimport '@namespace/util';\r\n\r\n.component {\r\n @include some-mixin-from-util;\r\n}\r\n```\r\n\r\n#### Potential Solution\r\nI could be very wrong here as this is a naive solution, but after reviewing how webpack's `resolve.alias` works, taking advantage of it seems like a decent approach. At build time, we could copy the elements from `projects.PROJECTNAME.architect.build.stylePreprocessorOptions.includePaths` that have prefixes into `resolve.alias` and be good to go. You'd have to reference your style file in your component's stylesheet via an `import '@namespace/util.scss'` but having to include the filetype doesn't seem to be the end of the world. If it won't break anything, we could even include `.scss,.css,.less` in the `resolve.extensions`.","author":{"url":"https://github.com/damienwebdev","@type":"Person","name":"damienwebdev"},"datePublished":"2018-10-12T16:08:51Z","url":"https://github.com/angular/angular-cli/issues/12573"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:fb432bba-65ff-055a-7bf2-e5f0cadb5603 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | BEDE:62F48:F4C605:1430330:6B020984 |
| html-safe-nonce | 82e410a342b5dc5adff7987b87163133f6e4153885415897c1c3982f7b3d6284 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCRURFOjYyRjQ4OkY0QzYwNToxNDMwMzMwOjZCMDIwOTg0IiwidmlzaXRvcl9pZCI6IjM2NTg3NTQ0OTY2MTM0NTIxNjQiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | e447b25f3d83fb2dbbd8dcf9b633ccb0f1705fe35a8f70bda44d652d9886c1b3 |
| hovercard-subject-tag | issue:369615854 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/angular/angular-cli/12573/issue_layout |
| twitter:image | https://opengraph.githubassets.com/a3acf58d888751b12ccc2bb865fff02b1ef4baace43cd9eabb0d108b5c17de27/angular/angular-cli/issues/12573 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/a3acf58d888751b12ccc2bb865fff02b1ef4baace43cd9eabb0d108b5c17de27/angular/angular-cli/issues/12573 |
| og:image:alt | Bug Report or Feature Request (mark with an x) - [ ] bug report -> please search issues before submitting - [x] feature request Command (mark with an x) - [ ] new - [] build - [] serve - [] test - ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | damienwebdev |
| hostname | github.com |
| expected-hostname | github.com |
| None | 87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456 |
| turbo-cache-control | no-preview |
| go-import | github.com/angular/angular-cli git https://github.com/angular/angular-cli.git |
| octolytics-dimension-user_id | 139426 |
| octolytics-dimension-user_login | angular |
| octolytics-dimension-repository_id | 36891867 |
| octolytics-dimension-repository_nwo | angular/angular-cli |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 36891867 |
| octolytics-dimension-repository_network_root_nwo | angular/angular-cli |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 423dbb54c5e7bfecc838eb387c1435eb3d0e760d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width