我无法进行汇总将我的ES6代码转换为ES5。它仍然在留言Warning: Error transforming main.js with 'babel' plugin: It looks like your Babel configuration specifies a module transformer. Please disable it. If you're using the "es2015" preset, consider using "es2015-rollup" instead. See https://github.com/rollup/rollup-plugin-babel#configuring-babel for more information Use --force to continue.
我的.babelrc
{
"presets": [
[
"es2015-rollup",
{
"modules": false
}
]
],
"plugins": ["external-helpers"]
}
我的.gruntfile
"use strict";
var babel = require('rollup-plugin-babel');
module.exports = function( grunt ) {
grunt.initConfig({
//...
rollup: {
options: {
plugins: function () {
return [
babel({
babelrc: false,
presets: ["es2015-rollup"]
})
];
},
},
main: {
'dest': 'build/js/bundle.js',
'src' : 'src/js/main.js',
},
},
//...
});
// Load the tasks
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-sass');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-notify');
grunt.loadNpmTasks('grunt-postcss');
grunt.loadNpmTasks('grunt-rollup');
grunt.registerTask( 'default', [ 'rollup', 'watch' ] );
//...
};
我的devDependencies
"devDependencies": {
"autoprefixer": "^6.2.3",
"babel-plugin-external-helpers": "^6.8.0",
"babel-preset-es2015": "^6.16.0",
"babel-preset-es2015-rollup": "^1.2.0",
"grunt": "^0.4.5",
"grunt-babel": "^6.0.0",
"grunt-contrib-sass": "^0.9.2",
"grunt-contrib-uglify": "^0.11.0",
"grunt-contrib-watch": "^0.6.1",
"grunt-notify": "^0.4.3",
"grunt-postcss": "^0.7.1",
"grunt-rollup": "^0.8.0",
"rollup-plugin-babel": "^2.6.1"
}
正如您所看到的,我使用了es2015-rollup
预设,而不是es2015
作为警告提示。另一件事是,如果我删除预设,我的代码根本没有被发现。
答案 0 :(得分:0)
plugins
选项应该是一个数组,而不是一个函数。
另外,在.babelrc
中,您应该使用es2015
而不是es2015-rollup
,因为汇总版本仅为es2015
插件{。}}。
答案 1 :(得分:0)
如果你设置babelrc:false,你的配置将不会读取 .babelrc 配置文件。
忽略您的 .babelrc 文件,并在 Gruntfile.js 中的babel插件配置中尝试此操作:
babel({
babelrc: false,
presets: [["es2015",{modules:false}]],
exclude: ['./node_modules/**/*'], //make sure to point to your folder path
plugins: ["external-helpers"]
})