Recently I was writing to learn how Rollup configured a packaged production environment. The rollup location is used to package the code base, Vue, React and other famous front boxes are also packaged based on rollup. But before you send a package, you need to install and test the package. (The tests here are divided into unit tests and installation tests)
The directory structure
External testpackage.json
Because there are fewer external packages installed, so
node_modules
There’s certainly not much in it. As follows:
The packagepackage.json
As you can see, there’s a lot more dependence on the inside, a lot more dependence on the outside.
The contents of the package
way
After my attempt, there are two ways, you can dozen the package, through the NPM way to install
Methods anpm install ./pack-name
Start the service, run the code,Here are the results:
Way 2npm link
NPM Link is used to establish a connection between a local project and ** local NPM modules (packages)** so that the module can be tested locally. For details, see the specific use mode:
Into the bag,npm link
在node
In the installation directory ofnode_global
To create a soft link
Use commands externally
- CD to the module directory, NPM link, for global link
- CD to the project directory, NPM link module name (name in package.json)
Start the service, run the code,Here are the results:
Change source code
Prove that NPM Link is the created soft link.
Expand the NPM
The way NPM installs the package, most people should be most affected by the NPM install package name, yes, yes, in fact NPM install can also accept other types of parameters.
Installation instructions | Meaning, for example | pagackage.json |
---|---|---|
npm install (with no args, in package dir) |
Do not use any parameters, directly is the package directory, can be your local package oh! eg:npm install ./mypackage |
"mypackage": "file:mypackage" . |
npm install [<@scope>/]<name> |
Use a warehouse under theA packageEg:npm install @rollup/babel |
"@ Babel/core", "^ 7.14.6" |
npm install [<@scope>/]<name> |
To use a package in a repository, eg:npm install @rollup/babel |
"@ Babel/core", "^ 7.14.6" |
npm install [<@scope>/]<name>@<tag> |
Install the latest version of the package, eg:npm install @babel/core@latest |
"@ Babel/core", "^ 7.14.6" |
npm install [<@scope>/]<name>@<version> |
Install the specified version of the package, eg:NPM install @ rollup/[email protected] |
"@ Babel/core", "^ 6.0.0" |
npm install [<@scope>/]<name>@<version range> |
Install a range of packages, eg:NPM install @ rollup/Babel @ "> = 6.0.0 < 7.14.6" |
"@ Babel/core", "^ 7.0.0." " |
npm install <alias>@npm:<name> |
Install a package with a custom alias, eg:npm install jquery2@npm:jquery@2 npm install jquery3@npm:jquery@3 |
"Jquery2" : "NPM: jquery @ ^ 2.2.4", "Jquery3" : "NPM: jquery @ ^ 3.6.0" |
See more
npm install (with no args, in package dir)
npm install [<@scope>/]<name>
npm install [<@scope>/]<name>@<tag>
npm install [<@scope>/]<name>@<version>
npm install [<@scope>/]<name>@<version range>
npm install <alias>@npm:<name>
npm install <git-host>:<git-user>/<repo-name>
npm install <git repo url>
npm install <tarball file>
npm install <tarball url>
npm install <folder>
Copy the code
This article uses the Article Synchronization Assistant to synchronize