首页 > 解决方案 > 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:

Thanks!

标签: npmwebpack

解决方案


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


推荐阅读