英文:
ampersand postcss-nested not working in create-react-app
问题
Ampersand doesn't work in styles (postcss)
package
npm i --dev autoprefixer postcss-nested postcss-cli npm-run-all
commands
"scripts": {
"start": "npm-run-all -p watch:css start-js",
"build": "npm-run-all build:css build-js",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject",
"build:css": "postcss src/styles/main.css -o src/index.css",
"watch:css": "postcss src/styles/main.css -o src/index.css -w",
"start-js": "react-scripts start",
"build-js": "react-scripts build"
}
postcss.config.js in the root
module.exports = {
plugins: [require("postcss-nested"), require("autoprefixer")],
};
code:
- index.css
.App {
background-color: #ffffff;
&-header {
background-color: yellow;
}
}
- App.js
<div className="App">
<header className="App-header">test</header>
</div>
why ampersand in code doesn't work?
英文:
Ampersand doesn't work in styles (postcss)
package
npm i --dev autoprefixer postcss-nested postcss-cli npm-run-all
commands
"scripts": {
"start": "npm-run-all -p watch:css start-js",
"build": "npm-run-all build:css build-js",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject",
"build:css": "postcss src/styles/main.css -o src/index.css",
"watch:css": "postcss src/styles/main.css -o src/index.css -w",
"start-js": "react-scripts start",
"build-js": "react-scripts build"
}
postcss.config.js in the root
module.exports = {
plugins: [require("postcss-nested"), require("autoprefixer")],
};
code:
- index.css
.App {
background-color: #ffffff;
&-header {
background-color: yellow;
}
}
- App.js
<div className="App">
<header className="App-header">test</header>
</div>
why ampersand in code doesn't work?
答案1
得分: 0
使用CRA时,需要编写npm eject
,然后才能编辑出现的配置更改。
如果您不想在运行npm eject
时获取所有配置,那么可以使用CRACO - 它允许您单独创建配置文件。
英文:
When using CRA, you need to write npm eject and only then write changes in the config that appears.
If you don't want to get all the configs when you write npm eject, then use CRACO - it allows you to create a file for configs separately
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论