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 |
|
7 | Default 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
|
19 | var bundl = require('bundl');
|
20 | var pack = require('bundl-pack');
|
21 | var write = require('bundl-write');
|
22 |
|
23 | var packOptions = {
|
24 | paths: ['/src/javascripts']
|
25 | };
|
26 |
|
27 | bundl('entry.js')
|
28 | .then(pack(packOptions))
|
29 | .then(write())
|
30 | .all();
|
31 | ```
|
32 |
|
33 | # Options
|
34 |
|
35 | ## .paths
|
36 | An 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
|
47 | Hide relative path names from require statements (`require('../path/file.js')` becomes `require(2)`)
|
48 | ```js
|
49 | {
|
50 | obscure: true
|
51 | }
|
52 | ```
|
53 |
|
54 | ## .[extension]
|
55 | Define processors and options for files of any type. See [plugins](https://github.com/seebigs/bundl/wiki/Popular-Plugins#modules--dependencies)
|
56 | ```js
|
57 | var babelProcessor = require('bundl-pack-babel');
|
58 | var 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 |
|
82 | If you want to package files manually, you can do the following:
|
83 |
|
84 | ```js
|
85 | var pack = require('bundl-pack');
|
86 |
|
87 | var packed = pack(options).one(entryFileContents);
|
88 |
|
89 | console.log(packed.contents);
|
90 | ```
|