安装软件包后运行npm脚本

问题描述 投票:0回答:1

我有一个简单的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

谢谢!

npm webpack
1个回答
0
投票

修复非常简单。只需在Webpack配置中将include替换为exclude

include: path.join(__dirname, 'sources'),

效果很好。

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

© www.soinside.com 2019 - 2024. All rights reserved.