1 | # coffee-inline-map
|
2 |
|
3 | Compile CoffeeScript files with inline source maps.
|
4 |
|
5 | ## Features
|
6 |
|
7 | * Error reporting similar to the original CoffeeScript compiler.
|
8 | * `.litcoffee` support.
|
9 |
|
10 | ## Example
|
11 |
|
12 | ```
|
13 | $ cat a.coffee
|
14 | module.exports = (something) -> console.log something
|
15 |
|
16 | $ coffee-inline-map a.coffee | fold -w72
|
17 | // Generated by CoffeeScript 1.10.0
|
18 | (function() {
|
19 | module.exports = function(something) {
|
20 | return console.log(something);
|
21 | };
|
22 |
|
23 | }).call(this);
|
24 |
|
25 | //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaW
|
26 | xlIjoiYS5jb2ZmZWUiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyJhLmNvZmZlZSJdLC
|
27 | JuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUE7RUFBQSxNQUFNLENBQUMsT0FBUCxHQUFpQi
|
28 | xTQUFDLFNBQUQ7V0FBZSxPQUFPLENBQUMsR0FBUixDQUFZLFNBQVo7RUFBZjtBQUFqQiIsIn
|
29 | NvdXJjZXNDb250ZW50IjpbIm1vZHVsZS5leHBvcnRzID0gKHNvbWV0aGluZykgLT4gY29uc2
|
30 | 9sZS5sb2cgc29tZXRoaW5nXG4iXX0=
|
31 |
|
32 | $ coffee-inline-map -h
|
33 | Usage: coffee-inline-map [options] [file.coffee]
|
34 |
|
35 | Available options:
|
36 | -h, --help output usage information & exit
|
37 | -V, --version output the version number & exit
|
38 | -o, --output [FILE] write result to a FILE instead of stdout
|
39 | -l, --literate treat stdin as literate style coffee-script
|
40 | -b, --bare compile without a top-level function wrapper
|
41 | --no-map don't include inline source map (why?)
|
42 |
|
43 | ```
|
44 |
|
45 | ## Installation
|
46 |
|
47 | # npm install -g coffee-inline-map
|
48 |
|
49 | ## Compilation
|
50 |
|
51 | $ make compile
|
52 |
|
53 | ## browserify & make-commonjs-depend
|
54 |
|
55 | To verify the text below you'll need to clone this repo, run 'make
|
56 | compile' & install
|
57 | [make-commonjs-depend](https://github.com/gromnitsky/make-commonjs-depend).
|
58 |
|
59 | Look into repo's `test/data` directory. Ignore `*.should` files. I'll wait.
|
60 |
|
61 | Then
|
62 |
|
63 | ```
|
64 | $ cd src
|
65 | $ ls *coffee
|
66 | a.coffee
|
67 | b.litcoffee
|
68 | main.coffee
|
69 |
|
70 | ```
|
71 |
|
72 | Here `main.coffee` depends on `a.coffee` & `b.litcoffee`. For out site
|
73 | we need just 1 `public/bundle.js` file which will include the result form the
|
74 | compilations of our all CoffeeScript files.
|
75 |
|
76 | We want to rebuild `public/bundle.js` only & only on .coffee files
|
77 | change. That's obviously a job for make.
|
78 |
|
79 | ```
|
80 | $ cat Makefile
|
81 | COFFEE_COMPILER := ../../../bin/coffee-inline-map
|
82 | BROWSERIFY := ../../../node_modules/.bin/browserify
|
83 |
|
84 | out := ../public
|
85 | js_temp := \
|
86 | $(patsubst %.coffee,%.js,$(wildcard *.coffee)) \
|
87 | $(patsubst %.litcoffee,%.js,$(wildcard *.litcoffee))
|
88 | bundle := $(out)/bundle.js
|
89 |
|
90 | .PHONY: depend compile compile-js clean
|
91 |
|
92 | all: compile
|
93 |
|
94 | %.js: %.coffee
|
95 | $(COFFEE_COMPILER) $< -o $@
|
96 |
|
97 | %.js: %.litcoffee
|
98 | $(COFFEE_COMPILER) $< -o $@
|
99 |
|
100 | depend: compile-js
|
101 | make-commonjs-depend *js -o js.mk
|
102 |
|
103 | -include js.mk
|
104 |
|
105 | compile-js: $(js_temp)
|
106 | compile: compile-js $(bundle)
|
107 |
|
108 | $(bundle): main.js
|
109 | @mkdir -p $(out)
|
110 | $(BROWSERIFY) -d $< -o $@
|
111 |
|
112 | clean:
|
113 | rm -f js.mk $(js_temp) $(bundle)
|
114 |
|
115 | ```
|
116 |
|
117 | To create a dependency tree, we run
|
118 |
|
119 | ```
|
120 | $ make depend
|
121 | ../../../bin/coffee-inline-map a.coffee -o a.js
|
122 | ../../../bin/coffee-inline-map main.coffee -o main.js
|
123 | ../../../bin/coffee-inline-map b.litcoffee -o b.js
|
124 | make-commonjs-depend *js -o js.mk
|
125 |
|
126 | ```
|
127 |
|
128 | ```
|
129 | $ cat js.mk
|
130 | a.js:
|
131 | b.js:
|
132 | main.js: \
|
133 | a.js \
|
134 | b.js
|
135 |
|
136 | ```
|
137 |
|
138 | It's unfortunate that make-commonjs-depend supports only
|
139 | javascript. That's why before running it, make needs to compile all
|
140 | coffescript files.
|
141 |
|
142 | Then compile the bundle
|
143 |
|
144 | ```
|
145 | $ make compile
|
146 | ../../../bin/coffee-inline-map main.coffee -o main.js
|
147 | ../../../node_modules/.bin/browserify -d main.js -o ../public/bundle.js
|
148 |
|
149 | ```
|
150 |
|
151 | As a little homework, try to guess why `main.js` was recompiled here,
|
152 | when at first glance it should rather not.
|
153 |
|
154 | Run again
|
155 |
|
156 | ```
|
157 | $ make compile
|
158 | make[1]: Nothing to be done for 'compile'.
|
159 |
|
160 | ```
|
161 |
|
162 | Notice that the nothing was recompiled for the 2nd time. That's our goal!
|
163 |
|
164 | ```
|
165 | $ touch a.coffee
|
166 | $ make compile
|
167 | ../../../bin/coffee-inline-map a.coffee -o a.js
|
168 | ../../../bin/coffee-inline-map main.coffee -o main.js
|
169 | ../../../node_modules/.bin/browserify -d main.js -o ../public/bundle.js
|
170 |
|
171 | ```
|
172 |
|
173 | Yay! Then open `public/index.html` in Chrome and switch to the console
|
174 | view. (Make sure to turn on 'Enable source maps' in Developer Tool's
|
175 | settings.)
|
176 |
|
177 | ## Jeez mate, why are you doing this rigmarole?
|
178 |
|
179 | Every dependency & every file should be compiled/processed only once.
|
180 |
|
181 | This seems meaningless for a bunch of small .coffee files but becomes
|
182 | very useful for large projects with several complex browserify output
|
183 | targets.
|
184 |
|
185 | ## Why not just use coffeeify plugin for browserify?
|
186 |
|
187 | 1. browserify can't (& shouldn't) check changes in our source files to
|
188 | decide whether it's time to recompile.
|
189 | 2. Error reporting.
|
190 |
|
191 | ## Why are you using outdated make instead of cake, jake, grunt, gulp or broccoli? It's not 1977 anymore!
|
192 |
|
193 | facepalm.jpg
|
194 |
|
195 | Dude. <br/>
|
196 | Take a walk for 10 minutes & no one will get hurt.
|
197 |
|
198 | ## BUGS
|
199 |
|
200 | * Reading from stdin doesn't work in Windows.
|
201 |
|
202 | ## NEWS
|
203 |
|
204 | ### 0.9.0
|
205 |
|
206 | * CoffeeScript 1.10.0.
|
207 |
|
208 | ### ...
|
209 |
|
210 | ### 0.5.0
|
211 |
|
212 | * CoffeeScript 1.8.0.
|
213 |
|
214 | ### 0.4.0
|
215 |
|
216 | * CoffeeScript 1.7.1
|
217 | * 'New' source map syntax.
|
218 |
|
219 | ### 0.3.0
|
220 |
|
221 | * `-b` CLO.
|
222 | * Include 'generated by ...' header.
|
223 |
|
224 | ### 0.2.0
|
225 |
|
226 | * Update for CoffeeScript 1.6.3.
|
227 | * Recognize `.coffee.md` extension.
|
228 | * `-l` CLO.
|
229 |
|
230 | ### 0.1.0
|
231 |
|
232 | * Add reading from stdin.
|
233 | * Fix an unheplful crash for EPIPE error.
|
234 |
|
235 | ## License
|
236 |
|
237 | MIT.
|