软件包安装后运行npm脚本

时间:2019-11-08 11:13:57

标签: npm webpack

我有一个简单的git仓库https://github.com/alexey-sh/test_webpack_with_npm

我想将其用作npm依赖项,但不发布在npm中。

换句话说,我想将软件包作为依赖项安装在另一个存储库中。

npm i --save git+https://github.com/alexey-sh/test_webpack_with_npm.git

但是我想在我的test_webpack_with_npm项目中使用现代js,并在安装软件包后将其编译为旧javascript。为此,我创建了npm脚本(test_webpack_with_npm软件包)

  "scripts": {
    "install": "npm run build",
    "build": "webpack --mode production --config webpack.config.js",
    "test": "echo \"Error: no test specified\" && exit 1"
  },

所以现在有一个奇怪的事情: 如果我从npm run build存储库中运行test_webpack_with_npm,则无需声明dist/index.js就可以得到class(正如我期望的那样)。 但是如果我通过以下命令安装软件包 npm i --save git+https://github.com/alexey-sh/test_webpack_with_npm.git 我得到了另一种dist/index.js类型,并且有class个声明。

如何正确安装test_webpack_with_npm?我想在node_modules/test_webpack_with_npm/dist/index.js中看到旧的js。

复制步骤:

  • mkdir my_test_project
  • cd my_test_project
  • npm init
  • npm i --save git+https://github.com/alexey-sh/test_webpack_with_npm.git
  • 检查node_modules / test_webpack_with_npm / dist / index.js

谢谢!

1 个答案:

答案 0 :(得分:0)

修复非常简单。只需用webpack配置中的include替换exclude

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -pthread" )

效果很好。

更新后的配置在这里https://github.com/alexey-sh/test_webpack_with_npm/blob/master/webpack.config.js

相关问题