我需要使用Grunt / grunt-contrib-uglify缩小一组
JSON文件(语言文件):
grunt.initConfig({ pkg: grunt.file.readJSON('package.json'),uglify: { build: { src: 'src/main/app/resources/locales/*/*.json',dest: 'target/resources/locales/*/*.json' } } });
我得到的是:
Files: src/main/app/resources/locales/en/messages.json -> target/*/*.json Minifying with UglifyJS...Reading src/main/app/resources/locales/en/messages.json...OK >> Uglifying source "src/main/app/resources/locales/en/messages.json" Failed. Warning: Uglification Failed. Use --force to continue.
我开始怀疑,uglify是否可用于纯JSON文件,还是仅用于JavaScript源文件? JSON文件确实很好,它以非最小化的形式在应用程序中运行.
解决方法
grunt-json-minify(如user2806181的答案所示)工作正常(顺便说一下,谢谢),但它只修改了文件.受到答案的启发,我发现了一个更高级的:
grunt-minjson:
grunt.initConfig({ pkg: grunt.file.readJSON('package.json'),minjson: { build: { files: { 'target/locales/en/messages.json': 'resource/locales/en/messages.json' } } } });