UNPKG

2.65 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## .exitProcessOnError
59A message will always be printed if a syntax error is encountered while packing. This option controls whether to halt the process or continue. Defaults to `true`.
60```js
61{
62 exitProcessOnError: false,
63}
64```
65
66## .leadingComments
67Display a comment at the top of every module showing the full module path. Defaults to `true`.
68```js
69{
70 leadingComments: false,
71}
72```
73
74## .obscure
75Hide relative path names from require statements (`require('../path/file.js')` becomes `require(2)`)
76```js
77{
78 obscure: true,
79}
80```
81
82## .paths
83An array of paths to use when resolving required/imported files
84```js
85{
86 paths: [
87 'src/javascripts',
88 'src/stylesheets',
89 ]
90}
91```
92
93## .[extension]
94Define processors and options for files of any type. See [plugins](https://github.com/seebigs/bundl/wiki/Popular-Plugins#modules--dependencies)
95```js
96var babelProcessor = require('bundl-pack-babel');
97var lessProcessor = require('bundl-pack-less');
98
99{
100 css: {
101 compatibility: 'ie8',
102 autoInject: false,
103 },
104 html: {
105 removeComments: false,
106 },
107 json: {
108 autoInject: false,
109 },
110 less: lessProcessor({
111 relativeUrls: false,
112 }),
113 js: babelProcessor({
114 presets: ['es2015'],
115 }),
116}
117```