简体   繁体   English

在 Next Js 项目 React SSR 中导入样式引导程序

[英]Import styles bootstrap in Next Js project React SSR

I have a problem that the styles are not loaded in next js.我有一个问题,样式未在下一个 js 中加载。 According to the official documentation , I can import css or scss files to next Js.根据官方文档,我可以将 css 或 scss 文件导入下一个 Js。 But when I add reactstrap and bootstrap to the project, the components work for me without problem, but not bootstrap styles.但是当我将 reactstrap 和 bootstrap 添加到项目中时,这些组件对我来说没有问题,但不是 bootstrap 样式。 The purpose is to create an React app with SSR.目的是使用 SSR 创建一个 React 应用程序。 I hope you can help me with that.我希望你能帮我解决这个问题。 Thanks in advance.提前致谢。

create a next.config.js and add code below for sass support创建 next.config.js 并在下面添加代码以支持 sass

const withSass = require("@zeit/next-sass");
module.exports = withSass({
  /* config options here */
});

create a style.scss创建一个 style.scss

@import url("https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css");

then import to your react component然后导入到你的反应组件

我认为你缺少添加@ zeit / next-css

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM