如何使用ES6与PhantomJS [英] How to use ES6 with PhantomJS
问题描述
我可以使用Babel将每个文件从ES6转移到ES5,但是保持并行树是尴尬的(一个在ES6中,另一个在ES5中),并将导入写入以要求ES5模块。我正在寻找一个更清洁的解决方案。
我可以删除所有导入和导出代码,将模块连接在一起,将结果转换成单个文件,然后运行PhantomJS,但是如果可能,我更愿意使用导入和导出。
我尝试使用Browserify与babelify变换将ES6依赖关系树分解为单个ES5文件,但是Browserify找不到像网页
提供的PhantomJS提供的模块。我尝试忽略这些模块,放入我的 package.json
:
浏览器:{
网页:false
}
但导入网页
返回一个空对象而不是PhantomJS模块。
是否有一个干净的方式使用ES6模块与PhantomJS?
Browserify的 - 排除
。
browserify --exclude网页-t babelify script.js --outfile compiled.js
phantomjs compiled.js
从依赖关系树中排除网页
离开导入到位。
Is there a way to use ES6 and modules with PhantomJS?
I can transpile each file from ES6 to ES5 using Babel, but it's awkward to maintain parallel trees (one in ES6 and another in ES5) and write the imports to require the ES5 modules. I'm looking for a cleaner solution.
I can remove all import and export code, concatenate the modules together, transpile the result into a single file, then run in through PhantomJS, but I'd prefer to use imports and exports if possible.
I tried using Browserify with the babelify transform to transpile the ES6 dependency tree into a single ES5 file, but Browserify can't find PhantomJS-provided modules like webpage
. I've tried ignoring those modules by putting in my package.json
:
"browser": {
"webpage": false
}
but importing webpage
returns an empty object instead of the PhantomJS module.
Is there a clean way to use ES6 modules with PhantomJS?
Browserify's --exclude
option does what I need.
browserify --exclude webpage -t babelify script.js --outfile compiled.js
phantomjs compiled.js
That excludes webpage
from the dependency tree but leaves the import in place.
这篇关于如何使用ES6与PhantomJS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!