【问题标题】:build script in package.json using webpack with --config flag as使用带有 --config 标志的 webpack 在 package.json 中构建脚本
【发布时间】:2023-03-09 00:13:01
【问题描述】:

在我的 package.json 中,我尝试在脚本中使用 webpack,但它一直失败。

  "scripts": {
    "start": "node server.js",
    "test": "mocha 'src/**/test*.coffee' --watch --compilers coffee:coffee-script/register",
    "build": "webpack --config webpack.dist.config.js"
  },

脚本 starttest 按预期工作,但在终端中运行 npm build 时,我什么也得不到:

➜  client git:(master) ✗ npm build
➜  client git:(master) ✗ 

手动运行命令时,会发生以下情况:

➜  client git:(master) ✗ webpack --config webpack.dist.config.js
Hash: 9274a04acd39605afc25
Version: webpack 1.9.10
Time: 5206ms
    Asset     Size  Chunks             Chunk Names
bundle.js  5.23 MB       0  [emitted]  main
   [0] multi main 28 bytes {0} [built]
 [349] ../config.js 181 bytes {0} [built]
    + 413 hidden modules
➜  client git:(master) ✗ 

我是否想念 npm 脚本的工作原理?

【问题讨论】:

    标签: npm


    【解决方案1】:

    使用:npm run build

    原因:npm start & npm testnpm run start & npm run test 的快捷方式,对于任何其他 npm 任务,您必须指定“运行”

    【讨论】:

      【解决方案2】:

      运行npm run build

      starttest 内置在 npm 的脚本中。但是build 是一个自定义脚本,因此需要使用npm run build 调用。

      你可以了解更多关于 npm 的脚本here

      【讨论】:

        猜你喜欢
        • 2020-08-31
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-06-30
        • 2012-07-11
        • 2021-02-15
        • 2017-06-24
        • 2021-09-05
        相关资源
        最近更新 更多