Webpack,Babel:ES6导入与Fabric.js的需求 [英] webpack, babel: es6 import vs. require for Fabric.js
问题描述
我在开发工具链中使用webpack和babel;运行以下代码时:
I am using webpack and babel in my development tool chain; when running the following code:
import * as fabric from 'fabric';
var canvas = new fabric.Canvas('canvas');
我收到以下错误:
_fabric2.default.Canvas is not a constructor
如果我使用require('fabric');
代替,则相同的代码可以正常工作
import
.
Whereas the same code works fine if I use require('fabric');
instead of
import
.
我尝试了不同的呼叫import
的方式,但是没有一个起作用.
I tried different ways of calling import
but none of them worked.
我的整理工具抱怨未定义的fabric
变量,因此我希望对其进行正确定义.令人惊讶的(对我来说),这段代码
也不起作用:
My linting tool complains of the undefined fabric
variable, so I would like to have it properly defined. Surprisingly (for me), this code
doesn't work neither:
var fabric = require("fabric");
在这种情况下,我收到以下错误消息:
I get the following error in this case:
fabric.Canvas is not a constructor
我在做什么错了?
推荐答案
在当前使用NPM中的fabric
设置中,我使用
In my current setup using fabric
from NPM, I use
import {fabric} from 'fabric'
import {fabric} from 'fabric'
访问结构全局对象.
这篇关于Webpack,Babel:ES6导入与Fabric.js的需求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!