Grunt babel 多个文件并保留源映射
Grunt babel multiple files and preserve source mapping
我正在尝试使用 grunt 和 babel 来转换文件夹中的所有 js6 文件,并最终得到一个串联的单个文件 (js5),其中包含原始 es6 文件的工作源映射。但是源映射不起作用。我的 babel,concat 设置如下:
"babel": {
options: {
sourceMap : true
},
dist: {
files:[
{
expand: true,
cwd: 'wwwroot/js/src',
src: ['*.js'],
dest: 'tmp/js'
}]
}
},
concat: {
options: {
sourceMap: true
},
js: {
src: [
'tmp/js/*.js',
],
dest: 'wwwroot/js/app.js'
}
}
Versions:
"grunt": "0.4.5",
"grunt-bower-task": "0.4.0",
"grunt-babel": "5.0.1",
"grunt-contrib-concat" : "0.5.1"
我首先得到一个包含大量 js 文件和 src 映射(tmp 目录)的文件夹。但是将它们合并到一个文件中会完全弄乱源映射。
想法?另外,我可以以某种方式跳过临时文件的制作,而只是将结果通过管道传输到 concat 中吗?
颠倒任务顺序会使 easier.First 运行 JS 文件上的 concat
任务。之后 运行 babel
任务在之前由 concat
任务创建的单个文件上使用以下选项
options: {
sourceMap: true,
inputSourceMap: grunt.file.readJSON('script.js.map')
},
这里的script.js.map
文件是concat
任务生成的source map文件名。由于 inputSourceMap
选项不包含源映射对象,我们使用 grunt.file API 的 readJSON
方法
将其传入
完整的 G运行t 文件配置为:
concat: {
options: {
sourceMap: true
},
js: {
src: ['Modules/**/js/*.js'],
dest: 'script.js'
}
},
babel: {
dist: {
options: {
sourceMap: true,
inputSourceMap: grunt.file.readJSON('script.js.map')
},
src: [
'script.js',
],
dest: 'app.js'
}
}
我正在尝试使用 grunt 和 babel 来转换文件夹中的所有 js6 文件,并最终得到一个串联的单个文件 (js5),其中包含原始 es6 文件的工作源映射。但是源映射不起作用。我的 babel,concat 设置如下:
"babel": {
options: {
sourceMap : true
},
dist: {
files:[
{
expand: true,
cwd: 'wwwroot/js/src',
src: ['*.js'],
dest: 'tmp/js'
}]
}
},
concat: {
options: {
sourceMap: true
},
js: {
src: [
'tmp/js/*.js',
],
dest: 'wwwroot/js/app.js'
}
}
Versions:
"grunt": "0.4.5",
"grunt-bower-task": "0.4.0",
"grunt-babel": "5.0.1",
"grunt-contrib-concat" : "0.5.1"
我首先得到一个包含大量 js 文件和 src 映射(tmp 目录)的文件夹。但是将它们合并到一个文件中会完全弄乱源映射。
想法?另外,我可以以某种方式跳过临时文件的制作,而只是将结果通过管道传输到 concat 中吗?
颠倒任务顺序会使 easier.First 运行 JS 文件上的 concat
任务。之后 运行 babel
任务在之前由 concat
任务创建的单个文件上使用以下选项
options: {
sourceMap: true,
inputSourceMap: grunt.file.readJSON('script.js.map')
},
这里的script.js.map
文件是concat
任务生成的source map文件名。由于 inputSourceMap
选项不包含源映射对象,我们使用 grunt.file API 的 readJSON
方法
完整的 G运行t 文件配置为:
concat: {
options: {
sourceMap: true
},
js: {
src: ['Modules/**/js/*.js'],
dest: 'script.js'
}
},
babel: {
dist: {
options: {
sourceMap: true,
inputSourceMap: grunt.file.readJSON('script.js.map')
},
src: [
'script.js',
],
dest: 'app.js'
}
}