Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
365 views
in Technique[技术] by (71.8m points)

ecmascript 6 - How to use ES6 with PhantomJS

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

According to PhantomJS dev's comment on GitHub, the full support of ES6 will come with PhantomJS 2.5.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...