如何在RequireJS项目中集成ES6模块语法 [英] How to integrate ES6 Module syntax in RequireJS project
问题描述
我正在寻找一种在我当前的RequireJS项目中使用ES6模块(导入/导出)语法的方法. 我可以直接在最近的浏览器中运行我的项目,而无需构建或Babel转换. 我仅使用r.js和Babel构建项目,用于生产.
I'm looking for a way to use ES6 Modules (import/export) syntax in my current RequireJS project. I can run my project directly in a recent browser, without build or Babel transformation. I build my project with r.js and Babel only for production.
我们想开始构建ES6模块并将其与requireJS一起使用. 有办法吗?
We would like to start building ES6 modules and use it with requireJS. Is there a way to do that ?
注意:RequireJS不会加载用ES6编写的依赖项.
NB : RequireJS does not load dependencies written in ES6.
推荐答案
Yes, RequireJS should be compatible with Babel's es2015-modules-umd plugin. So you should be able to use import
and export
in your files during development with a modern browser that supports modules, then use r.js and Babel w/that plugin for production.
这篇关于如何在RequireJS项目中集成ES6模块语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!