我想要将JavaScript错误记录到服务器,但在使用JS压缩代码时堆栈跟踪不太有用。因此,我考虑使用Getsentry或Rollbar,这两者都可借助
我遇到了以下错误:
"Destination (_build/js/app.js) not written because src files were empty."
一旦正确地创建源映射,就会出现另一个问题,即
以下是我的Gruntfile.js(我从中删除了一些内容)。
我不知道为什么会出现名为
请参考下面链接以获得更好的解决方案:
https://dev59.com/NnjZa4cB1Zd3GeqPgaMd#20574196 https://github.com/gruntjs/grunt-contrib-uglify/issues/39#issuecomment-14856100
sourcemap
显示适当的堆栈跟踪。但我无法首先创建。我遇到了以下错误:
"Destination (_build/js/app.js) not written because src files were empty."
一旦正确地创建源映射,就会出现另一个问题,即
rev
会重命名该文件。我还需要保留未压缩的连接文件。以下是我的Gruntfile.js(我从中删除了一些内容)。
module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
clean: {
jsFolders: {
src: [
'_build/js/ui',
'_build/js/vendor',
'_build/js/app',
'_build/js/*templates.js'
]
},
build: {
src: ['_build/**/*']
}
},
copy: {
build: {
files: [{
expand: true,
src: [
'index.html',
'img/**/*', //includes web.cofig also.
'img/**/*.svg',
'!img/**/*.psd',
'js/**/*', //includes web.cofig also.
'css/**/*', //includes web.cofig also.
'*.png',
'favicon.ico'
],
dest: '_build/'
}]
},
},
rev: {
option: {
algorithm: 'sha1',
length: 4
},
all: {
files: {
src: [
'_build/**/*.{js,css,eot,ttf,woff}'
]
}
}
},
useminPrepare: {
html: ['_build/index.html']
},
usemin: {
html: [
'_build/index.html'
],
css: [
'_build/css/**/*.css'
]
},
uglify: {
options: {
sourceMap: '_build/js/app.js.map',
},
js: {
files: {
'_build/js/app.js': ['_build/js/app.js']
}
}
},
cssmin: {
minify: {
expand: true,
cwd: '_build/css/',
src: '*.css',
dest: '_build/css/'
}
},
});
grunt.registerTask('build', [
'clean:build',
'handlebars',
'compass',
'autoprefixer',
'copy:build',
'useminPrepare',
'concat',
'uglify',
'cssmin',
'clean:jsFolders',
'rev',
'usemin',
]);
};
更新
尝试了@Andy的解决方案,仍然显示相同的错误"Destination (_build/js/app.js) not written because src files were empty."
并且在构建时还会显示下面的内容。
uglify:
{ options:
{ sourceMap: true,
sourceMapName: '_build/js/app.js.map' },
js: { files: { '_build/js/app.js': [ '_build/js/app.js' ] } },
generated:
{ files:
[ { dest: 'dist\\js\\app.js',
src: [ '.tmp\\concat\\js\\app.js' ] } ] } }
我不知道为什么会出现名为
dest
的名称。我的输出文件夹是_build
。
更新2:请参考下面链接以获得更好的解决方案:
https://dev59.com/NnjZa4cB1Zd3GeqPgaMd#20574196 https://github.com/gruntjs/grunt-contrib-uglify/issues/39#issuecomment-14856100