简体   繁体   English

在 es6 中使用 rollup.js

[英]Using rollup.js with es6

This is a follow-up question to How to set up rollup.js with a d3 plugin?这是如何使用 d3 插件设置 rollup.js 的后续问题? . .

I have little dummy module foo.js:我有一个小的虚拟模块 foo.js:

//.src/foo.js
import * as d3 from "d3";

export default function() {
  return d3.select("body").append("div").text(42); 
};

and an index.js:和一个 index.js:

export {default as foo} from "./src/foo";

for which I can apply rollup with the following rollup.config.js:我可以使用以下 rollup.config.js 应用汇总:

// rollup.config.js
import babel from "rollup-plugin-babel";
import * as meta from "./package.json";

export default {
  input: "index.js",
  external: ["d3"],
  output: {
    file: `build/${meta.name}.js`,
    name: "d3",
    format: "umd",
    indent: false,
    extend: true,
    // banner: `// ${meta.homepage} v${meta.version} Copyright ${(new Date).getFullYear()} ${meta.author}`,
    globals: {d3: "d3"},
    plugins: [
      babel({
        exclude: "node_modules/**"})
    ]
  },
};

This works fine.这工作正常。 However, if I add a es6 command like "const" to foo.js:但是,如果我在 foo.js 中添加一个像“const”这样的 es6 命令:

import * as d3 from "d3";

export default function() {
  const num = 42;
  return d3.select("body").append("div").text(num); 
};

I get an ERROR: Unexpected token: keyword «const» at JS_Parse_Error.get (eval at...)我收到一个错误:意外的令牌:JS_Parse_Error.get 处的关键字«const»(eval at...)

How do I have to update my rollup.config.js to make it work?我如何更新我的 rollup.config.js 以使其工作?

The error that came up is unrelated to rollup.js.出现的错误与 rollup.js 无关。 I missed that I run uglify-js which caused that problem...我错过了我运行导致该问题的 uglify-js ......

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM