UNPKG

1.98 kBMarkdownView Raw
1# bundl-pack
2
3*Pack project dependencies into one JS file. Easily include external HTML and CSS files as strings. Pre-process LESS, SASS, CoffeeScript, and more...*
4
5*Supports ES6 imports via [bundl-pack-babel](https://github.com/seebigs/bundl-pack-babel)*
6
7Default processors automatically handle the requiring/importing of the following extensions. (Default behavior can be modified or overriden, and [plugins already exist](https://github.com/seebigs/bundl/wiki/Popular-Plugins#modules--dependencies) to allow easy importing of many other popular file types)
8* json
9* css
10* html
11
12---
13
14```
15$ npm install --save-dev bundl-pack
16```
17
18```js
19var bundl = require('bundl');
20var pack = require('bundl-pack');
21var write = require('bundl-write');
22
23var packOptions = {
24 paths: ['/src/javascripts']
25};
26
27bundl('entry.js')
28 .then(pack(packOptions))
29 .then(write())
30 .all();
31```
32
33# Options
34
35## .paths
36An array of paths to use when resolving required/imported files
37```js
38{
39 paths: [
40 'src/javascripts',
41 'src/stylesheets'
42 ]
43}
44```
45
46## .obscure
47Hide relative path names from require statements (`require('../path/file.js')` becomes `require(2)`)
48```js
49{
50 obscure: true
51}
52```
53
54## .[extension]
55Define processors and options for files of any type. See [plugins](https://github.com/seebigs/bundl/wiki/Popular-Plugins#modules--dependencies)
56```js
57var babelProcessor = require('bundl-pack-babel');
58var lessProcessor = require('bundl-pack-less');
59
60{
61 css: {
62 compatibility: 'ie8',
63 autoInject: false
64 },
65 html: {
66 removeComments: false
67 },
68 json: {
69 autoInject: false
70 },
71 less: lessProcessor({
72 relativeUrls: false
73 }),
74 js: babelProcessor({
75 presets: ['es2015']
76 })
77}
78```
79
80# Stand-Alone Usage
81
82If you want to package files manually, you can do the following:
83
84```js
85var pack = require('bundl-pack');
86
87var packed = pack(options).one(entryFileContents);
88
89console.log(packed.contents);
90```