Let's say that we start with the following starter pack: https://github.com/angularclass/angular2-webpack-starter
After npm install
and npm run start
everything works fine.
I want to add an external css module, for example bootstrap 4's css (and only the css). (I know that bootstrap has a bootstrap-loader, but now I'm asking for general solution, so please think about bootstrap 4 here as it could be any other css module that is available via npm).
I install bootstrap via npm: npm install [email protected] --save
First I thought that it is enough to add import 'bootstrap/dist/css/bootstrap.css';
to the vendor.browser.ts file.
But it isn't.
What should I do to have a proper solution?
Solutions I'm NOT asking for:
Use an absolute path to import a CSS file from node_modules in React, e.g. import 'bootstrap/dist/css/bootstrap. min. css' . Make sure you have the specific package installed, omit the node_modules directory and start with the package name.
It is possible by using @import '~bootstrap/dist/css/bootstrap.css';
on the styles.css file. (Note the ~)
Edit: How it works - The '~' is an alias set on the webpack config pointing to the assets folder... simple as that..
Edit 2: Example on how to configure webpack with the '~' alias... this should go on the webpack config file (usually webpack.config.js
)...
// look for the "resolve" property and add the following... // you might need to require the asset like '~/bootsrap/...' resolve: { alias: { '~': path.resolve('./node_modules') } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With