【问题标题】:Error when trying to run CSS build in package.json尝试在 package.json 中运行 CSS 构建时出错
【发布时间】:2021-09-30 20:15:16
【问题描述】:

我正在尝试执行 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 构建脚本?

【问题讨论】:

    标签: javascript reactjs package.json


    【解决方案1】:

    您将脚本添加到 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 脚本冲突。

    【讨论】:

      猜你喜欢
      • 2021-03-05
      • 1970-01-01
      • 2020-10-26
      • 2021-01-22
      • 2012-07-07
      • 2015-09-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多