meltingice / CamanJS

Javascript HTML5 (Ca)nvas (Man)ipulation

Home Page:http://camanjs.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unable to use in webpack

bebbi opened this issue · comments

Is it possible to work around camanjs failing on node-canvas when using webpack to bundle it for browser?

My setup: ES6 project with node v6.3.0, babel6, webpack, (OSX).
After installing cairo, npm install works:

test-caman@0.1.0 /Users/me/test-caman
└─┬ caman@4.1.2
  └── canvas@1.6.2

On bundling the source with webpack:

Error in ./~/canvas/lib/bindings.js
Module not found: ../build/Release/canvas in /Users/me/test-caman/node_modules/canvas/lib

 @ ./~/canvas/lib/bindings.js 3:17-51

Error in ./~/fibers/fibers.js
Module parse failed: /Users/me/test-caman/node_modules/fibers/fibers.js 'return' outside of function (2:1)
You may need an appropriate loader to handle this file type.
SyntaxError: 'return' outside of function (2:1)
 @ ./~/caman/dist/caman.full.js 175:12-29

You can simply set 'export' to undefined and inject the window context with the imports-loader.

import 'imports-loader?exports=>undefined,require=>false,this=>window!caman-dist-only';

It should not work in that way, and also this method will not work with some bootstrap project like create-react-app. So can the environment be detected with more appropriate way?