Inpack is a cli tool that makes it possible to use any directory as a Node.js module. It helps in avoiding long relative paths (like import responseParser from '../../../utils/responseParser'
) in your "require" or "import" without creating any additional files apart from its own config file called inpack.json. Also provokes build more clean and clear project architecture. You can use inpack with depy.
Use
import ComponentName from 'ComponentName';
instead
import Component from './../../../components/dummy/ComponentName';
Install it globally:
$ npm install -g inpack
Suppose we have a project with the following structure:
~/Project:
Components
MainComponent
index.js
WelcomeComponent
index.js
index.js
package.json
Use next command in the project’s root directory (valid package.json is required):
~/Project $ inpack init
You It will create inpack.json.
Use "add" to add existing directory as a Node.js module and save data to inpack.json:
~/Project $ inpack add Component/MainComponent
From now on, your ‘Component/MainComponent' directory can be added anywhere in the project in following ways:
const MainModule = require('MainModule');
// or
import MainModule from 'MainModule';
In future, if you need to deploy the project (or just clone it from github), you can simply run ‘link’. For example:
~/Project $ npm install
~/Project $ inpack link
All of your components are good to go now.
Creates a new project in the current directory.
Available options:
--name
- project name (directory name by default)--prefix
- prefix for added modules. It makes sense using this option if you want to avoid conflicts with other modules. For example, suppose the project’s prefix is@Project/
. Then, a module namedMainComponent
can be accessed via@Project/MainComponent
. As a bonus, you always know that you are importing inpack module.--add-postinstall
- adds or modifies thepostinstall
attribute in the existing package.json by adding theinpack link
command.
Declares a directory as a Node.js module. Can be used in various ways:
inpack add <relative-path>
- adds specified directory as a module relative to the inpack master
inpack add
- adds current directory as a module.
For example:
~/Project $ inpack add Components/MainComponent
is equivalent to
~/Project/Components/MainComponent $ inpack add
Available options:
--name
- module name (directory name by default)--main
- main file, does the same as the "main" attribute from package.json does.index.js
by default.--create
- creates a directory and main file, in case if either the directory or main file doesn’t exist.
Removes specified module (from the configuration as well). Does not remove the source-directory. Can be used in various ways as well as ‘add’.
Available options:
--force
- removes the module even if it’s not declared in the configuration file.
Links all of the modules from inpack.json. Must be run from the master project.
Alias: resolve
Displays information about the module. Can be used in various ways as well as ‘add’ or ‘remove’.
Lists a brief information about all modules.
Available options:
--verbose
- lists the full information about all modules.
Also there is the —context-dir
option that is available for all of the commands and allows to specify a directory where you would like to run one or another command. For example:
~ $ inpack list
✖ Searching for master project
Master project has not been found
~ $ inpack list --context-dir ./Project
[There goes the command output]