我試圖在複製時將一些佔位符替換爲不同的文件。我的gruntfile工作正常,但在進程選項中添加替換項,它只是不起作用。下面是我gruntfile的相關章節:流程選項混亂的grunt-contrib-copy語法
grunt.initConfig({
copy: {
js: {
files: [{
expand: true,
cwd: 'src/wp-content/themes/pilau-starter/',
src: ['**/*.js'],
dest: 'public/wp-content/themes/pilau-starter/'
}],
options: {
process: function (content) {
console.log(content);
content = content.replace(/pilauBreakpointLarge/g, breakpoints.large);
content = content.replace(/pilauBreakpointMedium/g, breakpoints.medium);
return content;
}
}
},
}
});
的路徑可以在代碼在GitHub上加以理解:https://github.com/pilau/starter(public目錄不承諾回購,因爲這是一個入門的主題)。這些路徑是我原始的Gruntfile中的變量,並且在所有其他任務中工作正常。
所有的變量都設置好。我已經包含了console.log(content)
來檢查進程函數是否實際運行 - 它似乎不是,所以我想這是基本的語法。
有一個答案(https://stackoverflow.com/a/28600474/1087660)似乎解決了這個問題,但據我所知,這樣做的方式只是很糟糕的JS語法 - 不知道它是如何被標記爲正確的。
--verbose
輸出運行復制任務:
Running "copy:js" (copy) task
Verifying property copy.js exists in config...OK
Files: src/wp-content/themes/pilau-starter/js/admin.js -> public/wp-content/themes/pilau-starter/js/admin.js
Files: src/wp-content/themes/pilau-starter/js/flickity.js -> public/wp-content/themes/pilau-starter/js/flickity.js
Files: src/wp-content/themes/pilau-starter/js/global.js -> public/wp-content/themes/pilau-starter/js/global.js
Files: src/wp-content/themes/pilau-starter/js/modernizr.js -> public/wp-content/themes/pilau-starter/js/modernizr.js
Files: src/wp-content/themes/pilau-starter/js/picturefill.js -> public/wp-content/themes/pilau-starter/js/picturefill.js
Files: src/wp-content/themes/pilau-starter/js/respond.js -> public/wp-content/themes/pilau-starter/js/respond.js
Options: processContent=false, processContentExclude=[], process=undefined
Options: processContent=false, processContentExclude=[], process=undefined
Copying src/wp-content/themes/pilau-starter/js/admin.js -> public/wp-content/themes/pilau-starter/js/admin.js
Reading src/wp-content/themes/pilau-starter/js/admin.js...OK
Writing public/wp-content/themes/pilau-starter/js/admin.js...OK
如果您運行帶有'--verbose'標誌的任務有什麼輸出方法reponsible?另外,'nonull'選項在調試時會很有幫助。 – steveax
您使用的是哪個版本的'grunt-contrib-copy'?您可以嘗試使用'processContent'而不是'process',因爲它已在v0.4.1及更早版本中使用。你也可以嘗試控制檯登錄你的'breakpoints.large'和'breakpoints.medium',可能它們沒有在你的配置中正確設置... – nemesv
運行時文件是否被複制到輸出? +1 - 關於'--verbose'的建議。 – James