You can make this a lot cleaner by using the npm package and a webpack customisation.
If you first install bootstrap in your project:
npm install [email protected]
and make sure you can use sass-loader in your components:
npm install sass-loader node-sass --save-dev
now go to your webpack config file and add a sassLoader
object with the following:
sassLoader: {
includePaths: [
path.resolve(projectRoot, 'node_modules/bootstrap/scss/'),
],
},
projectRoot
should just point to where you can navigate to node_packages
from, in my case this is: path.resolve(__dirname, '../')
Now you can use bootstrap directly in your .vue
files and webpack will compile it for you when you add the following:
<style lang="scss">
@import "bootstrap";
</style>
To customise it I'd recommend pulling in the bootstrap _variables
first and then you can reference everything like normal, i.e.
@import "_variables";
// example customisation - I'd recommend importing a file here to store them all
$body-bg: $gray-dark;
// just place all your customisation work above the below import of bootstrap
@import "bootstrap";
This will mean you need to remove any CDN CSS versions or they could overwrite things, but you should now be able to fully customise bootstrap.
As another benefit this method allows you to strip out any bootstrap components you are not using. To do so rather than @import "bootstrap";
which is the entire bootstrap library, instead navigate to that file, i.e. node_modules/bootstrap/scss/bootstrap.scss
and then copy across the @import's you actually want. Essentially optimising your project...
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…