packmap
Turn a package.json into a browser-ready import map
Quickstart
Install the library:
npm install --save-dev packmap
Now add the following to your package.json:
{
"scripts": {
"build": "packmap"
}
}
And run the following:
npm run build
Explanation of packmap
Packmap will create a browser-ready directory and import map from a package.json file and node_modules. To use it, your packages must meet the following standards:
- All package.json
dependencies
must be in-browser dependencies instead of build-time dependencies. - There must be only one version of every package. Semantic versioning rules apply.
- Packages may have
directories.lib
in their package.json to specify which directory should be made available to the browser.
CLI usage
packmap
may be run as a CLI. To see the available options, run the following:
npx packmap --help
CLI Examples
packmap -o build
packmap -p ../my-package/package.json
packmap --override-map ./override-import-map.json
packmap --cwd ./subdir
Javascript usage
Packmap is a node package that is used as follows:
const packmap = require("packmap");
const options = {
outdir: "dist",
package: "path/to/package.json",
overrideMap: "path/to/override-map.json",
cwd: "./subdir",
log(message) {
console.log(message);
}
};
packmap(options)
.then(() => {
console.log("done!");
})
.catch(err => {
console.error(err);
});