sass没有在create-react-app中工作

时间:2018-04-06 12:44:12

标签: reactjs webpack sass create-react-app node-sass-chokidar

Sass没有在create-react-app中编译。当前的package.json结构是

{
  "name": "create-app",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "react": "^16.3.1",
    "react-dom": "^16.3.1",
    "react-scripts": "1.1.4"
  },
  "dependencies": {
    "node-sass-chokidar": "^1.2.2",
    "npm-run-all": "^4.1.2",
    "react": "^16.3.1",
    "react-dom": "^16.3.1",
    "react-redux": "^5.0.7",
    "react-router-dom": "^4.2.2",
    "react-scripts": "^1.1.4",
    "redux": "^3.7.2",
    "redux-logger": "^3.0.6",
    "redux-thunk": "^2.2.0"
  },
  "scripts": {
    "build-css": "node-sass-chokidar src/ -o src/",
    "watch-css": "npm run build-css && node-sass-chokidar src/ -o src/ --watch --recursive",
    "start-js": "react-scripts start",
    "start": "npm-run-all -p watch-css start-js",
    "build-js": "react-scripts build",
    "build": "npm-run-all build-css build-js",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject"
  }
}

回购:https://github.com/athimannil/create-app

enter image description here

2 个答案:

答案 0 :(得分:3)

工作正常,npm start按预期方式查看您的.scss个文件并输出.css个文件。

确保您的组件中需要.css个文件。

  

由于src/App.js仍导入src/App.css,因此样式将成为应用程序的一部分。您现在可以修改src/App.scss,并重新生成src/App.css

此外,由于现在生成.css个文件,您应该从SCM中删除它们。

  

此时,您可能希望从源代码管理中删除所有CSS文件,并将src/**/*.css添加到.gitignore文件中。

doc

答案 1 :(得分:1)

2. version of create-react-app现在支持Sass。安装node-sass(例如npm install node-sass)以启用它。检出此application's Navigation component