I am building a lib using TypeScript and Webpack.
To develop this library I have created a separate test project (written using JS) and linked the library using npm link <package-name>
.
The problem is that the link leads to the build file and I need to run npm run build
every time I make a change.
I want to have a link to the source file and have a live reload. Is it possible? Do I need to write my test project using TS also to make it possible?
Library package.json
:
{
...
"main": "lib/qr-code-styling.js",
"files": [
"lib"
],
"scripts": {
"build": "webpack --mode=production"
},
...
}
Code of the library https://github.com/kozakdenys/qr-code-styling/tree/v1
Code of test project https://github.com/kozakdenys/qr-code-styling-site
P.S. I also tried "module": "src/index.ts"
in package.json
, but it causes an error in the test project Uncaught Error: Cannot find module './core/QRCodeStyling'
Example: Let the local-dir is the local directory and project-dir is the project directory and local_module is the local module package you want to install, first go to the local-dir and type npm link and next go to the project directory and type npm link <local_module> this will link your local module to your project.
via npm. You can use npm to install TypeScript globally, this means that you can use the tsc command anywhere in your terminal. To do this, run npm install -g typescript . This will install the latest version (currently 4.7).
npm link just creates two symbolic links. When you run npm link in a module's root directory, npm creates a symbolic link from your “global node_modules” directory to the local module's directory. The “global node_modules” directory is a special directory where all modules installed with npm install -g are stored.
Another option is to have your TS project automatically rebuild using tsc --watch
and then use the compiled code in your project via npm link ../path/to/dep
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With