Angular CLI 'ng serve' to ignore less and

2019-05-29 09:09发布

问题:

I am using Angular CLI for Angular2 project. And I am using less for my styling.

To compile less file with Angular CLI, I have to import less file with its absolute path. Which breaks editor's intellisense. So instead of using LESSPlugin comes with AngularCLI, I want to use IDE's less watcher and compiler (available in vs code as well as webstorme) to compile less to css.

But there are less files still exists in source, 'ng serve' try to compile less and that breaks the build.

Is there any way to configure angular cli to ignore less file and use available css in source folder?

回答1:

I manage to do that by uninstalling less module from project using 'npm uninstall less --save-dev'

Now I can use relative path for less import and also intellisense is working now.



回答2:

When you generate a new project using angular cli, type a command like below:

ng new new-project --style less

It will setup your project using less. When you serve(run) the project each time, angular cli will automatically compile your less files.

According to ng command manual

ng new <options...>

--style (String) (Default: css)