UNPKG

5.1 kBMarkdownView Raw
1# coffee-inline-map
2
3Compile 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
14module.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
26xlIjoiYS5jb2ZmZWUiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyJhLmNvZmZlZSJdLC
27JuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUE7RUFBQSxNQUFNLENBQUMsT0FBUCxHQUFpQi
28xTQUFDLFNBQUQ7V0FBZSxPQUFPLENBQUMsR0FBUixDQUFZLFNBQVo7RUFBZjtBQUFqQiIsIn
29NvdXJjZXNDb250ZW50IjpbIm1vZHVsZS5leHBvcnRzID0gKHNvbWV0aGluZykgLT4gY29uc2
309sZS5sb2cgc29tZXRoaW5nXG4iXX0=
31
32$ coffee-inline-map -h
33Usage: coffee-inline-map [options] [file.coffee]
34
35Available 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
55To verify the text below you'll need to clone this repo, run 'make
56compile' & install
57[make-commonjs-depend](https://github.com/gromnitsky/make-commonjs-depend).
58
59Look into repo's `test/data` directory. Ignore `*.should` files. I'll wait.
60
61Then
62
63```
64$ cd src
65$ ls *coffee
66a.coffee
67b.litcoffee
68main.coffee
69
70```
71
72Here `main.coffee` depends on `a.coffee` & `b.litcoffee`. For out site
73we need just 1 `public/bundle.js` file which will include the result form the
74compilations of our all CoffeeScript files.
75
76We want to rebuild `public/bundle.js` only & only on .coffee files
77change. That's obviously a job for make.
78
79```
80$ cat Makefile
81COFFEE_COMPILER := ../../../bin/coffee-inline-map
82BROWSERIFY := ../../../node_modules/.bin/browserify
83
84out := ../public
85js_temp := \
86 $(patsubst %.coffee,%.js,$(wildcard *.coffee)) \
87 $(patsubst %.litcoffee,%.js,$(wildcard *.litcoffee))
88bundle := $(out)/bundle.js
89
90.PHONY: depend compile compile-js clean
91
92all: compile
93
94%.js: %.coffee
95 $(COFFEE_COMPILER) $< -o $@
96
97%.js: %.litcoffee
98 $(COFFEE_COMPILER) $< -o $@
99
100depend: compile-js
101 make-commonjs-depend *js -o js.mk
102
103-include js.mk
104
105compile-js: $(js_temp)
106compile: compile-js $(bundle)
107
108$(bundle): main.js
109 @mkdir -p $(out)
110 $(BROWSERIFY) -d $< -o $@
111
112clean:
113 rm -f js.mk $(js_temp) $(bundle)
114
115```
116
117To 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
124make-commonjs-depend *js -o js.mk
125
126```
127
128```
129$ cat js.mk
130a.js:
131b.js:
132main.js: \
133 a.js \
134 b.js
135
136```
137
138It's unfortunate that make-commonjs-depend supports only
139javascript. That's why before running it, make needs to compile all
140coffescript files.
141
142Then 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
151As a little homework, try to guess why `main.js` was recompiled here,
152when at first glance it should rather not.
153
154Run again
155
156```
157$ make compile
158make[1]: Nothing to be done for 'compile'.
159
160```
161
162Notice 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
173Yay! Then open `public/index.html` in Chrome and switch to the console
174view. (Make sure to turn on 'Enable source maps' in Developer Tool's
175settings.)
176
177## Jeez mate, why are you doing this rigmarole?
178
179Every dependency & every file should be compiled/processed only once.
180
181This seems meaningless for a bunch of small .coffee files but becomes
182very useful for large projects with several complex browserify output
183targets.
184
185## Why not just use coffeeify plugin for browserify?
186
1871. browserify can't (& shouldn't) check changes in our source files to
188 decide whether it's time to recompile.
1892. Error reporting.
190
191## Why are you using outdated make instead of cake, jake, grunt, gulp or broccoli? It's not 1977 anymore!
192
193facepalm.jpg
194
195Dude. <br/>
196Take 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
237MIT.