尝试 运行 CSS 在 package.json 中构建时出错

Error when trying to run CSS build in package.json

我正在尝试执行 bulma sass 教程中的第 5 步:

https://bulma.io/documentation/customize/with-node-sass/

我这样设置 packge.json:

  "devDependencies": {
    "bulma": "^0.9.3",
    "node-sass": "^6.0.1",
    "css:build": "node-sass --omit-source-map-url sass/mystyles.scss css/mystyles.css",
    "css:watch": "npm run css:build -- --watch",
    "start": "npm run css:watch"
  }

  "scripts": { //this one is for running the React app
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },

为了测试我的脚本,我 运行 命令

npm run css:build

但收到以下错误:

npm ERR! Missing script: "css:build"

如何更好地设置我的 CSS 构建脚本?

您将脚本添加到 devDependencies 而不是 scripts。试试这个:

  "devDependencies": {
    "bulma": "^0.9.3",
    "node-sass": "^6.0.1",
    // React(-scripts) dependencies here
  }

  "scripts": { //this one is for running the React app
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject",
    "css:build": "node-sass --omit-source-map-url sass/mystyles.scss css/mystyles.css",
    "css:watch": "npm run css:build -- --watch"
  },

我删除了教程的 start 脚本,因为它只是 css:watch 脚本的别名,并且与您原来的 start 脚本冲突。