I am a new Angular 2 user, and I have some problems with it.
Traditionally, we could use <link rel="stylesheet" href="node_modules/normalize.css/normalize.css" />
to import a css file, but I want to make Angular 2 to automatically import it using import
.
I tried to use the same way when I used Material 2:
// angular-cli-build.js
module.exports = function(defaults) {
return new Angular2App(defaults, {
vendorNpmFiles: [
'normalize-path/index.js',
]
});
};
// system-config.ts
const map: any = {
'normalize': 'vendor/normalize-path',
};
/** User packages configuration. */
const packages: any = {
'normalize': {main: 'index.js'},
};
// app.component.ts
import { normalize } from 'normalize-path';
The editor will complain:
Cannot find module 'normalize-path'.
And the code won't compile. But I really have no idea what was wrong.
Based on this answer, all needed to do was:
Install the normalize.css library:
Import it in your styles.css
Update for Angular 8
Install the normalize.css library:
Import it in your styles.css
With the current (
1.0.0-beta.15
) version of angular-cli, the solution is quite easy:npm i normalize.css
"../node_modules/normalize.css/normalize.css"
inapps[0].styles
in the config fileangular-cli.json
Note: If using Angular 7, the config file is now
angular.json
, and the path to normalise.css inapps[0].styles
should be"../node_modules/normalize.css/normalize.css"
.Example:
and simple add the css link to index.html
The accepted response doesn't seem to be working on app. I needed to remove the
../
in the path name.The angular.json styles bit should be something like this: