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.
import ComponentName from 'ComponentName';
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.
--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 named
MainComponentcan be accessed via
@Project/MainComponent. As a bonus, you always know that you are importing inpack module.
--add-postinstall- adds or modifies the
postinstallattribute in the existing package.json by adding the
inpack add [module/relative/path]
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.
~/Project $ inpack add Components/MainComponent
is equivalent to
~/Project/Components/MainComponent $ inpack add
--name- module name (directory name by default)
--main- main file, does the same as the "main" attribute from package.json does.
--create- creates a directory and main file, in case if either the directory or main file doesn’t exist.
inpack remove [module name]
Removes specified module (from the configuration as well). Does not remove the source-directory. Can be used in various ways as well as ‘add’.
--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.
inpack info [module name]
Displays information about the module. Can be used in various ways as well as ‘add’ or ‘remove’.
Lists a brief information about all modules.
--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]