【发布时间】:2019-04-26 06:28:42
【问题描述】:
SASS 源地图无法在 create-react-app 2 (reported bug) 上输出,在考虑正式修复时一直在尝试寻找解决方法。
另一位用户建议将以下内容添加到脚本中:
"scripts": {
"build-css": "node-sass --source-map true --include-path ./src --include-path ./node_modules src/assets/sass -o public/css",
"watch-css": "npm run build-css && node-sass --source-map true --include-path ./src --include-path ./node_modules src/assets/sass -o public/css --watch --recursive"
这样做可以解决问题,但会生成另一个 CSS,该 CSS 会在 webpack 之外被拾取,同时也会破坏 CSS 注入(热加载)。
这就是包含 CSS 的方式(通过 index.js 文件中的 import)。理想情况下,这应该保持原样。
import "styles/main.scss";
在 package.json 下(react-scripts v2.1.1):
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"lint": "NODE_ENV=production eslint src --ext '.js,.jsx'",
"lint-fix": "yarn lint --fix",
"lint-check": "NODE_ENV=production eslint --print-config . | eslint-config-prettier-check",
"prepare-mobile": "node prepare-mobile.js",
"release-mobile": "node prepare-mobile-release.js",
"postbuild": "yarn prepare-mobile",
"precommit": "pretty-quick --staged"
}
除了上述方法,还有什么方法可以输出 SASS 源图而不必弹出 webpack?
【问题讨论】:
-
在github.com/facebook/create-react-app/issues/5707 中了解agairing 对Firefox 的临时修复。您还可以在此处查看代码更改:github.com/facebook/create-react-app/pull/6472/commits/…。我可以确认这对我有用。希望对您有所帮助!
标签: reactjs webpack create-react-app package.json