parcel-processor
v1.1.1
Published
write asset files to a package directry given an entry point
Readme
parcel-processor
write asset files to a package directory given an entry point
example
Given an entry point on process.argv[2], create a browserify bundle and write
the inline assets to opts.dst:
var copier = require('parcel-processor');
var browserify = require('browserify');
var path = require('path');
var file = path.resolve(process.argv[2]);
copier(browserify(file), {
keys: [ 'style' ],
dst: __dirname + '/dst'
});methods
var copier = require('parcel-processor')var cp = copier(b, opts)
Given a browserify instance b and some
options opts, copy asset files from the
parcel-map output to the destination
opts.dst.
The options are:
opts.dst- the destination root to start writing package files atopts.keys- array of keys for parcel-map to read from the package.jsonopts.defaults- object of default values passed directly through to parcel-map
The return value is an event emitter cp with some events documented below.
events
cp.on('bundle.css', function (file) {})
When the concatenated css bundle has been written, this event fires with the file path.
cp.on('bundle.js', function (file) {})
When the concatenated js bundle has been written, this event fires with the file path.
cp.on('package', function (pkg) {})
This event fires when a package is being written.
pkg has these properties:
pkg.isParcel- whether the package is a parcelpkg.package- the package.json contentspkg.assets- an array of assets paths declared inpkgpkg.id- the package.json identifier from parcel-mappkg.files- an object mapping theopts.keystypes to arrays of matching file paths for each typepkg.path- the path to the package root containing a package.jsonpkg.dependencies- an array of dependency ids thatpkgdepends onpkg.hash- the hash name used for the asset directory
Example pkg output:
{ package:
{ view: 'view.html',
main: 'main.js',
style: '*.css',
__dirname: '/home/substack/projects/parcel-processor/example/views/page1' },
assets: [ '/home/substack/projects/parcel-processor/example/views/page1/x.css' ],
id: '2814e2ae0d4b530be5c8adee15a7d5ce16246f96',
files: { style: [ '/home/substack/projects/parcel-processor/example/views/page1/x.css' ] },
path: '/home/substack/projects/parcel-processor/example/views/page1',
dependencies: [],
hash: '5c1f45e9747e602cfcda7c2b390b6779d11acb80' }cp.on('map', function (map) {})
This event fires when the asset map from parcel-map is available.
cp.on('done', function () {})
When the package and all dependent packages are completely written, this event fires.
install
With npm do:
npm install parcel-processorlicense
MIT

