Grunt-在Powershell转换为Json后无法读取Json文件
我现在有一个很奇怪的问题 我正在创建grunt缓存断路器使用的文件列表。我使用以下powershell脚本生成文件列表:Grunt-在Powershell转换为Json后无法读取Json文件,powershell,gruntjs,powershell-3.0,Powershell,Gruntjs,Powershell 3.0,我现在有一个很奇怪的问题 我正在创建grunt缓存断路器使用的文件列表。我使用以下powershell脚本生成文件列表: $ScriptDir = Split-Path $script:MyInvocation.MyCommand.Path $file = @{} #GET HTML FILES $Dir = get-childitem $ScriptDir\Helix -recurse $file = $Dir | where {$_.extension -eq ".html" } |
$ScriptDir = Split-Path $script:MyInvocation.MyCommand.Path
$file = @{}
#GET HTML FILES
$Dir = get-childitem $ScriptDir\Helix -recurse
$file = $Dir | where {$_.extension -eq ".html" } | % {$_.FullName}
#END
$file | convertto-jSon | out-file $ScriptDir\htmlfiles.json
这将生成一个包含以下内容的文件
[
"C:\\test\test1.html",
"C:\\test\test1.html",
"C:\\test\test1.html"
]
我的缓存断路器代码是:
module.exports = function(grunt) {
grunt.initConfig({
listOfHtmlPaths: grunt.file.readJSON('htmlfiles.json'),
cachebreaker: {
dev: {
options: {
match: ['.js', '.css', 'min.css'],
src:
{ path: 'Helix/**/*' }
},
files:
{ src: ['<%= listOfHtmlPaths %>'], }
},
},
});
grunt.loadNpmTasks('grunt-cache-breaker');
grunt.registerTask('default', ['cachebreaker']);
};
module.exports=函数(grunt){
grunt.initConfig({
ListOfHTMLPath:grunt.file.readJSON('htmlfiles.json'),
缓存破坏程序:{
开发人员:{
选项:{
匹配:['.js','.css',min.css'],
src:
{path:'Helix/***'}
},
文件夹:
{src:[''],}
},
},
});
loadNpmTasks('grunt-cache-breaker');
registerTask('default',['cachebreaker']);
};
运行powershell后,我运行Grunt,但出现以下错误:
错误:无法解析“bustAFile.json”文件(意外标记?)
如果我将bustAFile.json的全部内容复制到一个新的记事本文件中,则根本不会更改任何内容并保存它。它起作用了
Poweshell是否添加了一些我看不到的奇怪编码?强制powershell以ASCII编码输出解决了我的问题
$file | convertto-jSon -Compress | out-file $ScriptDir\bustAFile.json -encoding ascii
在解析JSON时,Grunt似乎无法读取其他编码