sass - Lazy load application theme styles with Angular CLI -


i trying switch href of <link /> theming purposes , scss themes live in packages folder of monorepo symlinked in node_modules. need able compile , reference these.

i came across following fixed issue: angular/angular-cli#3401 , have been trying implement similar:

"styles": [     "styles.scss",     {         "input": "../node_modules/@org/themes/dark.scss",         "output": "dark",         "lazy": true     } ], 

my understanding (perhaps incorrect) compile dark.scss file dist/dark.bundle.css , able load via http://localhost:4200/dist/dark.bundle.css not working expected. misunderstanding or doing wrong?

how compile scss file node_modules can lazy load in app? there another/better approach try instead?

additional notes:

  • using angular version 4.2.4
  • using angular cli version 1.3.0
  • the documentation approach
  • i working in monorepo node_modules/@org/themes symlink
  • i have tried using ng serve --preserve-symlinks option in case above issue. made no difference

i have looked way angular material docs website approaches problem , seems have custom build script compiles scss files css files in assets directory before serving application. thought fixed issue above removed need step perhaps not. way can done?

solved

thanks @kuncevic. missing --extract-css flag.

working config:

"styles": [     "styles.scss",     {         "input": "../node_modules/@org/themes/src/dark.scss",         "output": "themes/dark",         "lazy": true     } ], 

and following serve script, can access via http://localhost:4200/themes/dark.bundle.css:

ng serve --extract-css --preserve-symlinks

by setting "lazy": true means won't appear in index.html there no mechanism lazy load bundle you, check comment:

the lazy option doesn't lazy load anything. prevents being executed on application startup.

i agree "lazy": true bit confusing @ first.

if run ng build can see what's gets outputed in build , analyze files produced cli.

when do:

{     "input": "../node_modules/@org/themes/dark.scss",     "output": "dark",     "lazy": true } 

you should able access file directly @ http://localhost:4200/dark.bundle.js wont appear in index.html set "lazy": true

if want dark.bundle.css bundle instead of dark.bundle.js in dev mode can use --extract-css flag.

the reason why cli generating styles in js bundle in dev mode because way quicker. bud when prod build ng buld --prod output in .css default anyway.


Comments

Popular posts from this blog

Sort a complex associative array in PHP -

vb.net - How to ignore if a cell is empty nothing -

recursion - Can every recursive algorithm be improved with dynamic programming? -