【问题标题】:Using ES6 modules with WebPack, why require still needed将 ES6 模块与 WebPack 一起使用,为什么仍然需要 require
【发布时间】:2014-10-23 08:03:26
【问题描述】:

在下面的代码示例中,为什么注释行不能导入标记?我正在使用https://github.com/shama/es6-loader

module $ from 'jquery';
module React from 'react';

//import { marked } from 'marked';
var marked = require("marked");

这是一个示例存储库:https://github.com/justin808/react-tutorial-hot/tree/es6

此演示显示: 1. Webpack 和热重载 2. 反应 3. ES6

【问题讨论】:

标签: javascript require reactjs webpack


【解决方案1】:

您正在使用 destructuring operator,如果没有要解构的内容,它将无法工作,即 marked 导出函数。

import marked from 'marked' 应该可以工作。

【讨论】:

  • 有道理!我还没试过。跳过“require”有什么好处?
【解决方案2】:

es6-loader 使用 es6-module-transpiler 声明

ES6 模块语法仍在经历大量变动,可能会在最终批准之前发生变化。

可能还不支持所描述的语法?

【讨论】:

    猜你喜欢
    • 2019-09-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-15
    相关资源
    最近更新 更多