Jackie Jackie - 4 months ago 15
TypeScript Question

How do I configure BaconJS with Webpack and Coffee

I am porting legacy code to Webpack and I have the following...

Dependency loader in TS

import "baconjs/dist/Bacon.js"

Module in Coffee

@stream = new Bacon.Bus()

When I try to run I get

zone.js?fad3:269 Uncaught ReferenceError: Bacon is not defined

I tried adding this to my webpack config....

new webpack.ProvidePlugin({
Bacon: "Bacon"

But it did not help.

Module not found: Error: Cannot resolve module 'Bacon' in ...

What can I do to solve this?


The previous answer was on the right track but I was hesitant to have to include Bacon = require("baconjs/dist/Bacon.js") on each coffee script file that required it. So I went ahead and added the following to my Typescript dependencies file...

window['Bacon'] = require('baconjs/dist/Bacon.js');

This seems to have worked and does not require a require ;-) on each coffeescript file individually.

I originally tried

window.Bacon = require('baconjs/dist/Bacon.js');

But Typescript doesn't like it (How do you explicitly set a new property on `window` in TypeScript?)