npm - run npm script after package installing
问题描述
I have a simple git repository https://github.com/alexey-sh/test_webpack_with_npm
I want to use it as npm dependency but without publishing in npm.
So in other words I want to install the package in my another repository as dependency.
npm i --save git+https://github.com/alexey-sh/test_webpack_with_npm.git
But I want to use a modern js in my test_webpack_with_npm
project and compile it into old javascript after package installation process. To achieve it I created npm scripts (test_webpack_with_npm package)
"scripts": {
"install": "npm run build",
"build": "webpack --mode production --config webpack.config.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
so now there's a weird thing:
if I run npm run build
from test_webpack_with_npm
repository I can get dist/index.js
without class
declaration (as I expected).
but if I install the package via the following command
npm i --save git+https://github.com/alexey-sh/test_webpack_with_npm.git
I get another type of dist/index.js
and there are class
declaration.
How can I install the test_webpack_with_npm
properly? I want to see old js in node_modules/test_webpack_with_npm/dist/index.js
.
Steps to reproduce:
mkdir my_test_project
cd my_test_project
npm init
npm i --save git+https://github.com/alexey-sh/test_webpack_with_npm.git
- check node_modules/test_webpack_with_npm/dist/index.js
Thanks!
解决方案
the fix is very simple. just replace exclude with include in webpack config
include: path.join(__dirname, 'sources'),
that works perfectly.
updated config goes here https://github.com/alexey-sh/test_webpack_with_npm/blob/master/webpack.config.js
推荐阅读
- html - HTML按钮在按下之前被执行
- sql - SQL:获取具有条件逻辑 (CASE WHEN) 的两个字段 (DATEDIFF) 的计算的聚合 (SUM)
- php - 从默认库重命名按钮
- scala - 除非终止,否则 Scala 未来不会写入资源目录
- multithreading - 如何从另一个线程(Glib 线程)中取消一个线程?
- javascript - 确保承诺失败
- php - 使用 PHP 变量绑定查询结果
- bash - Mac Mojave 完全禁用了我的本地主机
- grep - Grep 重定向在 log.txt 中提取我想要的更多信息
- azure - 如果 count 参数设置为 0,则条件资源将被销毁