Skip to content

Instantly share code, notes, and snippets.

@mainiak
Last active September 10, 2015 23:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mainiak/1ae02e2694054f5fa6be to your computer and use it in GitHub Desktop.
Save mainiak/1ae02e2694054f5fa6be to your computer and use it in GitHub Desktop.
webpack vs coffee-script
*.swp
*~
bundle.js
node_modules
node-v4.0.0

Demo

About

This demo shows how Webpack & CoffeeScript should work together

Usage

git clone https://gist.github.com/1ae02e2694054f5fa6be.git
npm install
node ./index.js

Output

# Errors
./main.coffee
Module parse failed: /Users/jvitak/git/projects/test/main.coffee Line 1: Unexpected string
You may need an appropriate loader to handle this file type.
| Dummy = require './Dummy'
|
| d1 = new Dummy
# Warnings

Tested with

Links

class Dummy
constructor: (@text = "Hello world!") ->
print: ->
console.log @text
module.exports = Dummy
#!/usr/bin/env node
var webpack = require('webpack')
var config = require('./webpack.config')
// returns a Compiler instance
webpack(config, function (err, stats) {
if (err) {
throw err
}
var jsonStats = stats.toJson()
if (stats.hasErrors) {
console.log('# Errors')
jsonStats.errors.forEach(function (error) {
console.log(error)
})
}
if (stats.hasWarnings) {
console.log('# Warnings')
jsonStats.warnings.forEach(function (warning) {
console.log(warning)
})
}
})
Dummy = require './Dummy'
d1 = new Dummy
d2 = new Dummy 'some random text'
d1.print()
d2.print()
{
"name": "webpack-coffee-test",
"version": "0.0.1",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "https://gist.github.com/1ae02e2694054f5fa6be.git"
},
"author": "",
"license": "MIT",
"bugs": {
"url": "https://gist.github.com/1ae02e2694054f5fa6be"
},
"homepage": "https://gist.github.com/1ae02e2694054f5fa6be",
"dependencies": {
"coffee-loader": "^0.7.2",
"coffee-script": "^1.10.0",
"webpack": "^1.12.1"
}
}
module.exports = {
debug: true,
entry: './main',
loaders: [
//{ test: /\.(png|jpg)$/, loader: 'url-loader?limit=8192'},
//{ test: /\.css$/, loader: 'style!css' },
{ test: /\.coffee$/, loader: 'coffee' }
],
resolve: {
// you can now require('file') instead of require('file.coffee')
extensions: ['', '.js', '.json', '.coffee']
},
output: {
filename: 'bundle.js'
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment