-
Notifications
You must be signed in to change notification settings - Fork 2k
using coffee-script with webpack #4276
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
Comments
I'd say the error message is pretty self-explanatory: don't require coffeescript directly, use a loader. Googling "webpack coffeescript loader" gave me https://github.com/webpack/coffee-loader as the first result. Also, please try to refrain using github issues as a help forum – it's better to use StackOverflow. |
I am trying to use CoffeScript.compile("coffeescript string code") in browser so loader won't work, that is why I posted here. |
Future traveler: I'm struggling with the same issue. Seems to not be an unreasonable thing to want (for example, the coffeescript.org website). I was wanting to do this for the purpose of writing an Electron app. My solution was to use IPC to communicate between the browser and the renderer. The browser is a node environment, so I compile it there and then send it back. |
@timhuff using the built library file works for me so I added it as npm package called |
@Radivarig You're a life-saver, man. That's so much nicer. Thanks. |
You want |
I built a custom fork for my project with compiler API exposed for webpack. Just import { compile } from 'coffee-script' |
@akfish how does your fork compare with https://github.com/webpack-contrib/coffee-loader? As in, why would someone use your fork rather than coffee-loader? |
@GeoffreyBooth The issue is not compiling coffeescript with webpack. It's using the |
@GeoffreyBooth coffee-loader works at compile time, not runtime. |
Can you post a minimal example app of what you’re trying to accomplish? It sounds like you want to |
@GeoffreyBooth I don't think anyone's still attempting to do this. @Radivarig's tool solved it for me. @akfish was simply contributing his work for future visitors. |
@GeoffreyBooth But to answer your question, yea, the idea is to write something along the lines of: coffee = require 'coffee-script'
output = coffee.compile userInput And then package that up inside webpack |
import { compile } from 'coffee-script'
// User input coffee source
let src = editor.text;
// Compile it in browser
let compiledCode = compile(src, opts)
// Run compiled code or whatever
doStuffWith(compiledCode) Or imagining tools like codepen, jsfiddle, jsperf and etc if they want to add coffee support. In the good old days, one can simply include the compiled coffeescript bundle with Basically that's how this issue arises. |
That and what @timhuff said. |
Does webpack not support bundling of NPM packages through // some file in a webpack bundle
import { compile } from 'coffeescript'
let compiledCode = compile(src, opts) |
@connec Coffee-script's main script contains references to nodejs-only modules. Hence it cannot be packed. The alternative is to set a browser field in package.json pointing to a browser-specific entry script. I'll send a PR later. |
@akfish I see! That makes sense. Perhaps any file-handling logic should be moved into |
When I require with webpack
var CoffeeScript = require ('coffee-script')
I get the following outputif I include a fatter 160kb local file of coffer-script-1.9.3-min.js everything works but I'd like to avoid adding library build to source if possible.
Any ideas? Thanks
The text was updated successfully, but these errors were encountered: