1 | # compiled
|
2 | > Compiles the ES* bundle to your NodeJS version on install
|
3 |
|
4 | [![NPM][compiled-icon] ][compiled-url]
|
5 |
|
6 | [![Build status][compiled-ci-image] ][compiled-ci-url]
|
7 | [![semantic-release][semantic-image] ][semantic-url]
|
8 |
|
9 | Read [JavaScript needs the compile step (on install)](http://glebbahmutov.com/blog/javascript-needs-compile-step/) blog post. If you want to precompile bundles instead of asking the client to do
|
10 | this, see [pre-compiled](https://github.com/bahmutov/pre-compiled).
|
11 |
|
12 | ## Install and use
|
13 |
|
14 | npm install -S compiled
|
15 |
|
16 | Add the configuration to your project's `package.json` file
|
17 | (I am assuming the root source file is `src/main.js`)
|
18 |
|
19 | ```json
|
20 | "config": {
|
21 | "compiled": {
|
22 | "dir": "dist",
|
23 | "files": ["src/main.js"]
|
24 | }
|
25 | }
|
26 | ```
|
27 |
|
28 | You can list multiple files in `files` list - each bundle will be processed separately.
|
29 |
|
30 | Define the following scripts in the `package.json`
|
31 |
|
32 | ```json
|
33 | {
|
34 | "scripts": {
|
35 | "build": "build",
|
36 | "postinstall": "compile"
|
37 | },
|
38 | "main": "dist/main.compiled.js"
|
39 | }
|
40 | ```
|
41 |
|
42 | ## Multiple bundles
|
43 |
|
44 | Good example is the [left-behind](https://github.com/bahmutov/left-behind) repo.
|
45 | It has the main code and a bin script. Each is compiled separately.
|
46 |
|
47 | ## Force features
|
48 |
|
49 | You can force features to the list, maybe they are not detected by the feature tests.
|
50 | For example, to support the [new string repeat method](http://es6-features.org/#StringRepeating)
|
51 |
|
52 | ```json
|
53 | "config": {
|
54 | "compiled": {
|
55 | "dir": "dist",
|
56 | "files": ["src/main.js"],
|
57 | "features": ["StringMethods"]
|
58 | }
|
59 | }
|
60 | ```
|
61 |
|
62 | Use the names returned by ES feature tests
|
63 |
|
64 | ## Debug and development
|
65 |
|
66 | If you run this code using `DEBUG=compiled` variable, it will print debug log messages.
|
67 | For example
|
68 |
|
69 | $ DEBUG=compiled npm run build
|
70 | > compiled@0.0.0-semantic-release test-build /Users/kensho/git/compiled
|
71 | > node bin/build.js src/main.js
|
72 | compiled building from +0ms src/main.js
|
73 | compiled saved bundle +69ms dist/bundle.js
|
74 | compiled scanning for es features +39ms dist/bundle.js
|
75 | compiled used ES features +15ms [ 'arrow', 'letConst', 'templateString' ]
|
76 | compiled saved file with found es features +3ms dist/es6-features.json
|
77 |
|
78 | ### Small print
|
79 |
|
80 | Author: Gleb Bahmutov © 2016
|
81 |
|
82 | * [@bahmutov](https://twitter.com/bahmutov)
|
83 | * [glebbahmutov.com](http://glebbahmutov.com)
|
84 | * [blog](http://glebbahmutov.com/blog/)
|
85 |
|
86 | License: MIT - do anything with the code, but don't blame me if it does not work.
|
87 |
|
88 | Spread the word: tweet, star on github, etc.
|
89 |
|
90 | Support: if you find any problems with this module, email / tweet /
|
91 | [open issue](https://github.com/bahmutov/compiled/issues) on Github
|
92 |
|
93 | ## MIT License
|
94 |
|
95 | Copyright (c) 2016 Gleb Bahmutov
|
96 |
|
97 | Permission is hereby granted, free of charge, to any person
|
98 | obtaining a copy of this software and associated documentation
|
99 | files (the "Software"), to deal in the Software without
|
100 | restriction, including without limitation the rights to use,
|
101 | copy, modify, merge, publish, distribute, sublicense, and/or sell
|
102 | copies of the Software, and to permit persons to whom the
|
103 | Software is furnished to do so, subject to the following
|
104 | conditions:
|
105 |
|
106 | The above copyright notice and this permission notice shall be
|
107 | included in all copies or substantial portions of the Software.
|
108 |
|
109 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
110 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
111 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
112 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
113 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
114 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
115 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
116 | OTHER DEALINGS IN THE SOFTWARE.
|
117 |
|
118 | [compiled-icon]: https://nodei.co/npm/compiled.png?downloads=true
|
119 | [compiled-url]: https://npmjs.org/package/compiled
|
120 | [compiled-ci-image]: https://travis-ci.org/bahmutov/compiled.png?branch=master
|
121 | [compiled-ci-url]: https://travis-ci.org/bahmutov/compiled
|
122 | [semantic-image]: https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg
|
123 | [semantic-url]: https://github.com/semantic-release/semantic-release
|
124 |
|