【发布时间】:2020-11-07 06:28:07
【问题描述】:
我在我的项目中使用scss 和css。我有两个文件styles.css 和styles.css。我在_app.js 中导入了这两个文件
import "../styles.scss";
import Head from "next/head";
import React from "react";
import App from "next/app";
import "../styles.css";
在style.css
a {
color: red;
}
在我的styles.scss
body {
background-color: aqua
}
但是background color 没有设置。我不知道为什么没有设置。我还使用scss loader 来编译我的scss 文件。
这是我的代码 https://codesandbox.io/s/sharp-jennings-upb7y?file=/styles.scss:0-33
注意 ::T运行这个项目你需要创建新的终端并运行命令npm run dev。因为它运行在3004端口
我的webpack-config
const withSass = require("@zeit/next-sass");
module.exports = (phase, { defaultConfig }) => {
return withCss(
withSass({
webpack(config, { isServer }) {
config.module.rules.push({
rules: [
{
test: /\.s[ac]ss$/i,
use: [
{
loader: "sass-loader",
options: {
additionalData: `$public_font_url: ${process.env.NEXT_PUBLIC_FONTS};`
}
}
]
}
]
});
return config;
}
})
);
};
【问题讨论】:
-
NOTE ::To run this project you need to create new terminal and run a command npm run dev. because it run on 3004 port -
我运行代码并成功运行,包括 css 和 scss
-
你见过body背景色吗?
-
不是主体 bgc,但所有其他属性都可以正常工作
-
no..我的本地机器上的行为与我问这个问题的原因相同。我认为我的 webpack 配置错误
标签: javascript reactjs webpack next.js