-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CoffeeScript support for vue-cli and parcel templates #1467
Changes from all commits
7e4fd93
bebbdb8
62682e6
61e7315
b411ea9
c8c51ba
c4508bd
6304745
08443a5
a0a0333
d40ce45
6d415d3
7cd03ed
38579d2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ import vueStyleLoader from '../../transpilers/vue/style-loader'; | |
import cssLoader from '../../transpilers/vue/css-loader'; | ||
import base64Transpiler from '../../transpilers/base64'; | ||
import pugTranspiler from '../../transpilers/pug'; | ||
import coffeeTranspiler from '../../transpilers/coffee'; | ||
|
||
import Preset from '../'; | ||
|
||
|
@@ -127,6 +128,10 @@ export default function initialize() { | |
vuePreset.registerTranspiler(module => /\.vue$/.test(module.path), [ | ||
{ transpiler: vueTranspiler }, | ||
]); | ||
vuePreset.registerTranspiler(module => /\.coffee$/.test(module.path), [ | ||
{ transpiler: coffeeTranspiler }, | ||
{ transpiler: babelTranspiler }, | ||
]); | ||
|
||
registerStyleTranspilers(); | ||
|
||
|
@@ -148,7 +153,7 @@ export default function initialize() { | |
{ transpiler: noopTranspiler }, | ||
]); | ||
vuePreset.registerTranspiler(() => true, [{ transpiler: rawTranspiler }]); | ||
vuePreset.registerTranspiler(m => m.path.endsWith('pug'), [ | ||
vuePreset.registerTranspiler(module => /\.pug$/.test(module.path), [ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I updated the |
||
{ transpiler: pugTranspiler }, | ||
]); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { buildWorkerError } from '../utils/worker-error-handler'; | ||
|
||
self.importScripts( | ||
`${process.env.CODESANDBOX_HOST || ''}/static/js/coffeescript.2.3.2.js` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it be better to pull this from a CDN instead of including this always? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, I think it doesn't really matter where we get it from. CDN works too, might be a bit faster even, but not noticeably I think. |
||
); | ||
self.postMessage('ready'); | ||
|
||
self.addEventListener('message', event => { | ||
const { code, path } = event.data; | ||
|
||
try { | ||
const compiled = CoffeeScript.compile(code, { | ||
filename: path, | ||
sourceFiles: [path], | ||
bare: true, | ||
literate: false, | ||
inlineMap: true, | ||
sourceMap: false, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I removed the |
||
}); | ||
return self.postMessage({ | ||
type: 'result', | ||
transpiledCode: compiled, | ||
}); | ||
} catch (err) { | ||
return self.postMessage({ | ||
type: 'error', | ||
error: buildWorkerError(err), | ||
}); | ||
} | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// @flow | ||
import CoffeeWorker from 'worker-loader?publicPath=/&name=coffee-transpiler.[hash:8].worker.js!./coffee-worker.js'; | ||
|
||
import WorkerTranspiler from '../worker-transpiler'; | ||
import { type LoaderContext } from '../../transpiled-module'; | ||
|
||
class CoffeeTranspiler extends WorkerTranspiler { | ||
worker: Worker; | ||
|
||
constructor() { | ||
super('coffee-loader', CoffeeWorker, 1); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep! I think 1 is enough for the amount of coffee files in a project (since |
||
|
||
this.cacheable = false; | ||
} | ||
|
||
doTranspilation(code: string, loaderContext: LoaderContext) { | ||
return new Promise((resolve, reject) => { | ||
const path = loaderContext.path; | ||
|
||
this.queueTask( | ||
{ | ||
code, | ||
path, | ||
}, | ||
loaderContext._module.getId(), | ||
loaderContext, | ||
(err, data) => { | ||
if (err) { | ||
loaderContext.emitError(err); | ||
|
||
return reject(err); | ||
} | ||
|
||
return resolve(data); | ||
} | ||
); | ||
}); | ||
} | ||
} | ||
|
||
const transpiler = new CoffeeTranspiler(); | ||
|
||
export { CoffeeTranspiler }; | ||
|
||
export default transpiler; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -122,6 +122,7 @@ export default function(content: string, loaderContext: LoaderContext) { | |
ts: ['ts-loader'], | ||
typescript: ['ts-loader'], | ||
pug: ['pug-loader'], | ||
coffee: ['babel-loader', 'coffee-loader'], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is the 'babel-loader' needed to make this work? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, wow. I'm glad I asked! :-) |
||
}; | ||
|
||
const loaders = Object.assign({}, defaultLoaders, codeSandboxLoaders); | ||
|
Large diffs are not rendered by default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I originally added this
coffee
transpiler to the end of the file, but realized that it was not being executed since the level or declaration determines its priority and it was lower than theraw-loader
.