我用于 Bootstrap v5
nuxt.config.js
css: [
'~/assets/scss/main.scss',
],
styleResources: {
scss: [
'~/node_modules/bootstrap/scss/_functions.scss',
'~/node_modules/bootstrap/scss/_variables.scss',
'~/node_modules/bootstrap/scss/_mixins.scss',
'~/node_modules/bootstrap/scss/_containers.scss',
'~/node_modules/bootstrap/scss/_grid.scss'
]
},
modules: [
'@nuxtjs/style-resources',
],
@nuxtjs/style-resources 在组件中提供 mixins、变量、网格:
https://www.npmjs.com/package/@nuxtjs/style-resources
示例:
<style scoped lang="scss">
.header {
@include make-container();
}
</style>
main.scss
@import "bootstrap-configuration";
@import "bootstrap-optional";
@import "@/node_modules/bootstrap/scss/helpers";
@import "@/node_modules/bootstrap/scss/utilities/api";
@import "custom";
_bootstrap-configuration.scss
@import "bootstrap-required";
@import "@/node_modules/bootstrap/scss/utilities";
_bootstrap-optional.scss
(我只能包含我想要的内容)
@import "@/node_modules/bootstrap/scss/root";
@import "@/node_modules/bootstrap/scss/reboot";
@import "@/node_modules/bootstrap/scss/type";
@import "@/node_modules/bootstrap/scss/images";
@import "@/node_modules/bootstrap/scss/containers";
@import "@/node_modules/bootstrap/scss/grid";
@import "@/node_modules/bootstrap/scss/tables";
@import "@/node_modules/bootstrap/scss/forms";
@import "@/node_modules/bootstrap/scss/buttons";
@import "@/node_modules/bootstrap/scss/transitions";
@import "@/node_modules/bootstrap/scss/dropdown";
@import "@/node_modules/bootstrap/scss/button-group";
@import "@/node_modules/bootstrap/scss/nav";
@import "@/node_modules/bootstrap/scss/navbar";
@import "@/node_modules/bootstrap/scss/card";
@import "@/node_modules/bootstrap/scss/accordion";
@import "@/node_modules/bootstrap/scss/breadcrumb";
@import "@/node_modules/bootstrap/scss/pagination";
@import "@/node_modules/bootstrap/scss/badge";
@import "@/node_modules/bootstrap/scss/alert";
@import "@/node_modules/bootstrap/scss/progress";
@import "@/node_modules/bootstrap/scss/list-group";
@import "@/node_modules/bootstrap/scss/close";
@import "@/node_modules/bootstrap/scss/toasts";
@import "@/node_modules/bootstrap/scss/modal";
@import "@/node_modules/bootstrap/scss/tooltip";
@import "@/node_modules/bootstrap/scss/popover";
@import "@/node_modules/bootstrap/scss/carousel";
@import "@/node_modules/bootstrap/scss/spinners";
_custom.scss
(这里我放了一些变量来覆盖 Bootstrap 和组件的自定义 css)
$theme-colors: (
"red": #cf142b,
"black": #000,
"tan": #e0d9c7,
"blue": #009eba,
"blue-light": #d6e3e6,
"blue-dark": #006985,
"red-dark": #7d212b,
);
@import
'mixins/mixins';
@import
'_base/colors',
'_base/typography',
'_base/headings';
@import
'components/_page-header',
'components/text-editor',
'components/content-with-side-image',
'components/featured-artists',
'components/video-player',
'components/audio-player',
'components/call-to-action',
'components/divider',
'components/tabs',
'components/image-gallery',
'components/logos',
'components/button',
'components/page-submenu',
'components/page-submenu-target';
我的想法来自
https://v5.getbootstrap.com/docs/5.0/customize/optimize/