V
V
Valentine2018-11-20 15:28:38
Angular
Valentine, 2018-11-20 15:28:38

Angular cli: how to add angularjs component styles to ngUpgrade hybrid project?

Welcome all!
Right now I'm busy translating to a hybrid angular/angularjs project. And I ran into a problem with importing styles.
For example, a simple angularJs component:

import template from './simple.html';
import controller from './simple.controller.js';

import './simple.less'; // <-- Look at

export const SimpleComponent = {
  template,
  controller
};

In this case, I expect styles to be extracted from a file and then added to projects. Before switching to angular-cli all the magic worked because of 'MiniCssExtractPlugin'.
If I write components in angular:
@Component({
  selector: 'app-simple',
  templateUrl: './simple.html'
  styleUrls: ['./simple.less']
})

That all styles are added correctly. Similarly, if I add styles via:
angular.json -> (путь) projects.projectName.architect.build.options.styles 
"styles": [ "src/assets/styles/index.less" ]

The styles are also picked up.
Now I see 2 ways to solve the problem (the first one does not work or I misunderstood it, the second one I will use as a last resort):
1) Add "extractCss":true option to angular.cli -> projects.projectName.architect.serve .options. But it doesn't work. I opened an issue on github about "extractCss" : . But maybe I don't really understand what "extractCss" means and am mistakenly delegating 'MiniCssExtractPlugin' functionality to it?
2) Create 'app.less' in 'src/app' folder and add all component styles there via '@import' less , i.e. :
@import './main/components/simple/simple.less';
@import './main/components/awesome-input/awesome-input.less';
@import './main/components/awesome-button/awesome-button.less';
@import './main/components/awesome-scroll/awesome-scroll.less';
...

Then add this file to
angular.json -> (путь) projects.projectName.architect.build.options.styles 
"styles": [ "src/app/app.less" ]

But in this case, I think that this is an overhead for this task, and I'm missing some detail.
Thank you for your attention)

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question