In addition to @Louis answer, assuming you already have a group of third-party libraries specified in the require.js configuration in your new ES6 modules, whenever you import a module, be it amd or es6, you'll be while you keep the name of the imported module consistent. For instance:
Here is the gulpfile:
gulp.task("es6", function () { return gulp.src("modules/newFolder//es6/*.js") .pipe(babel({ "presets": ["es2015"], "plugins": ["transform-es2015-modules-amd"]
Here is the es6 file:
import d3 from 'd3'; import myFunc from 'modules/newFolder/es6module'
This will compile like this:
define(['d3', 'modules/newFolder/es6module'], function (_d, _myFunc) { 'use strict';
while the module in define(['d3', 'modules/newFolder/es6module'], ... compiled file is fine in the original AMD file, it should work with the existing require.js installation, for example, compress files, etc.
Regarding the @coderC question about require.js loaders, I used i18n!nls/lang in AMD modules, at first I thought it would be very difficult to find an alternative plugins for AMD plugins in ES6 modules, and I switched to other localization tools, such like i18next . But it turned out that everything is in order:
import lang from 'i18n!nls/lang'; // import other modules..
because it will be compiled using the gulp task to:
define(['d3', 'i18n!nls/lang'], function (_d, _lang) {
Thus, we do not need to worry about the require.js loader.
In a nutshell, in ES6 modules, if you want to use existing AMD plugins / modules, you just need to make sure that the compiled file matches the existing setting. Alternatively, you can try connecting the ES6 Rollup module to link all new ES6 files.
Hope this will be useful for anyone trying to integrate ES6 syntax into a project.