UNPKG

2.41 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 overridden, 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# Use as a plugin
15
16```
17$ npm install --save-dev bundl-pack
18```
19
20```js
21var Bundl = require('bundl');
22var pack = require('bundl-pack');
23var write = require('bundl-write');
24
25var packOptions = {
26 paths: ['/src/javascripts'],
27};
28
29new Bundl('entry.js')
30 .then(pack(packOptions))
31 .then(write())
32 .go();
33```
34
35# Use standalone
36
37If you want to just pass a String of contents and return the packaged result, you can do the following:
38
39```js
40var pack = require('bundl-pack');
41var fileContents = '...';
42var packed = pack.create(fileContents, options);
43console.log(packed);
44```
45
46---
47
48# Options
49
50## .allowCircular
51By default, circular dependencies will throw an error. Set this option to `true` to suppress this error and continue packaging anyways.
52```js
53{
54 allowCircular: true,
55}
56```
57
58## .leadingComments
59Display a comment at the top of every module showing the full module path. Defaults to `true`.
60```js
61{
62 leadingComments: false,
63}
64```
65
66## .obscure
67Hide relative path names from require statements (`require('../path/file.js')` becomes `require(2)`)
68```js
69{
70 obscure: true,
71}
72```
73
74## .paths
75An array of paths to use when resolving required/imported files
76```js
77{
78 paths: [
79 'src/javascripts',
80 'src/stylesheets',
81 ]
82}
83```
84
85## .[extension]
86Define processors and options for files of any type. See [plugins](https://github.com/seebigs/bundl/wiki/Popular-Plugins#modules--dependencies)
87```js
88var babelProcessor = require('bundl-pack-babel');
89var lessProcessor = require('bundl-pack-less');
90
91{
92 css: {
93 compatibility: 'ie8',
94 autoInject: false,
95 },
96 html: {
97 removeComments: false,
98 },
99 json: {
100 autoInject: false,
101 },
102 less: lessProcessor({
103 relativeUrls: false,
104 }),
105 js: babelProcessor({
106 presets: ['es2015'],
107 }),
108}
109```