简体   繁体   English

将ES6模块与WebPack一起使用,为什么还需要它

[英]Using ES6 modules with WebPack, why require still needed

In the code sample below, why does the commented line not work to import marked? 在下面的代码示例中,为什么注释行无法导入标记? I'm using the https://github.com/shama/es6-loader 我正在使用https://github.com/shama/es6-loader

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

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

Here's a sample repository: https://github.com/justin808/react-tutorial-hot/tree/es6 这是一个示例存储库: https//github.com/justin808/react-tutorial-hot/tree/es6

This demo shows: 1. Webpack and hot-reload 2. React 3. ES6 此演示显示:1。Webpack和热重载2. React 3. ES6

You're using the destructuring operator which won't work if there is nothing to destructure, ie marked exports a function. 你正在使用解构运算符 ,如果没有什么可以解构,那就不会工作,即marked导出函数。

import marked from 'marked' should work though. import marked from 'marked'应该可行。

The es6-loader uses the es6-module-transpiler which states that es6-loader使用es6-module-transpiler来说明这一点

The ES6 module syntax is still undergoing a lot of churn, and will likely change before final approval. ES6模块语法仍然经历了大量的流失,并且可能在最终批准之前发生变化。

Maybe the described syntax is not supported yet? 也许不支持所描述的语法?

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

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