Javascript 咕噜+;巴贝尔成功运行,但没有';我什么也不做
我是grunt/npm的新手,但在阅读了文档之后。我为自己制作了一个Javascript 咕噜+;巴贝尔成功运行,但没有';我什么也不做,javascript,node.js,npm,gruntjs,grunt-babel,Javascript,Node.js,Npm,Gruntjs,Grunt Babel,我是grunt/npm的新手,但在阅读了文档之后。我为自己制作了一个package.json和一个grunfile.js。以下是我的文件夹结构: / |- src |- myfile.es6 |- anotherfile.es6 |- etc. |- Gruntfile.js |- package.json 我所拥有的 这是我的Grunfile: module.exports = function(grunt) { require('load-grunt-ta
package.json
和一个grunfile.js
。以下是我的文件夹结构:
/
|- src
|- myfile.es6
|- anotherfile.es6
|- etc.
|- Gruntfile.js
|- package.json
我所拥有的 这是我的
Grunfile
:
module.exports = function(grunt) {
require('load-grunt-tasks')(grunt);
grunt.initConfig({
babel: {
options: {
sourceMap: true,
plugins: ['es2015']
},
dist: {
files: [{
expand: true,
cwd: 'src/',
src: ['*.es6'],
dest: 'dist/',
ext: '.js'
}]
}
}
});
grunt.registerTask('default', ['babel'])
};
然后是我的包.json
:
{
"name": "Cheddar",
"version": "0.2.0",
"devDependencies": {
"babel-preset-es2015": "^6.6.0",
"grunt": "^1.0.1",
"grunt-babel": "^6.0.0"
},
"scripts": {
"test": "grunt --verbose"
}
}
它有什么作用?
我有我的src/
文件夹,其中包含我的源文件(*.es6
)。我想用grunt将这些文件传输到dist/
目录
我试过的
然后,我使用npm安装
和npm更新--save
看起来不错,所以我继续跑,咕哝着:
$ grunt
Running "babel:dist" (babel) task
Done.
$ ls
Gruntfile.js node_modules/ package.json src/
ls
正在输出与我运行grunt
之前完全相同的内容。因此,似乎什么也没有发生。我的输出dist
在哪里?这几个小时来一直困扰着我。我已经尝试安装了babelify
,以及互联网上博客上的许多其他修复程序,但遗憾的是,没有任何效果。请尝试自述文件中的一个更直接的示例,如:
grunt.initConfig({
babel: {
options: {
sourceMap: true,
presets: ['es2015']
},
dist: {
files: {
'dist/myfile.js': 'src/myfile.es6'
}
}
} });
完成该工作后,请尝试在文件下指定*.es6
等。如果你看看grunt babel插件的源代码,它可能比你想象的要有限
您也可以使用npm脚本
直接指定babel命令行,我觉得这比使用grunt更简单。尝试使用关键字“presets”而不是“plugins”:
当我使用您的配置时,grunt似乎出错了,因为它找不到名为“es2015”的插件。在我做了更改之后,一切都正常了。另外,您可以将其添加到.babelrc文件:{“预设”:[“es2015”]},这样您就不必在Grunfile配置中担心它了。
babel: {
options: {
sourceMap: true,
presets: ['es2015']
}
...
}