使用babel与@babel/node

安装

yarn add -D @babel/cli @babel/node

编译entry-server.js

yarn babel ./src/ssr/entry-server.js  --presets=@babel/preset-env
var hello = () => {
  return "Hello World";
};

console.log(hello());

结果

"use strict";

require("core-js/modules/es6.array.iterator");

require("core-js/modules/es6.promise");

require("core-js/modules/es7.promise.finally");

var hello = function hello() {
  return "Hello World";
};

console.log(hello());

Done in 2.28s.

编译并运行entry-server.js

yarn babel-node ./src/ssr/entry-server.js  --presets=@babel/preset-env
var hello = () => {
  return "Hello World";
};

console.log(hello());

结果

Hello World
Done in 2.90s.
posted @ 2019-01-30 18:37  灯塔下的守望者  阅读(1608)  评论(0编辑  收藏  举报