我目前正在使用 Vagrant/Virtualbox 开发环境。我的 web 项目是一个 django/Angularjs 项目,其中所有前端开发脚手架都是用早午餐完成的。
当我使用 brunch build
命令时,Brunch 工作正常,但是当我使用 brunch watch
命令时,当我对主机上的项目进行更改时,我的 javascript 文件不会被 brunch 处理。
我试过使用 nfs 文件夹同步 config.vm.synced_folder folder["map"], folder["to"], type: folder["type"] ||= "nfs"
和默认的 Virtualbox 文件夹同步,但似乎都不适用于 brunch watch
。
以下是我的 brunch-config.js 文件:
exports.config = {
paths: {
watched: [
'app',
'assets',
'styles',
'vendor',
]
},
files: {
javascripts: {
joinTo: {
'javascript/app.js': /^app/,
'javascript/vendor.js': /^(vendor|bower_components)/,
}
},
stylesheets: {
joinTo: {
'styles/app.css': /^styles/,
'styles/vendor.css': /^(vendor|bower_components)/,
}
}
},
conventions: {
assets: function(path) {
/**
* Loops every path and returns path|true|false according what we need
* @param path file or directory's path
* @returns path if it is a directory
* true if it fit with the regular expression
* false otherwise
*
*/
if( /\/$/.test(path) ) return path;
// /^app\/.*\.html/.test(path) ||
// RegExp for anything we need
return /assets[\\/]/.test(path)
|| /.*(?:\.eot|\.svg|\.ttf|\.woff2|\.woff)/.test(path);
}
},
plugins: {
afterBrunch: [
'mv public/bootstrap/dist/fonts/* public/fonts',
'rm -r public/bootstrap',
'mv public/bootstrap-material-design/dist/fonts/* public/fonts/',
'rm -r public/bootstrap-material-design',
]
}
}
最佳答案
您可能需要启用轮询模式文件监视才能成功检测已挂载的文件系统之间的更改。
在你的早午餐配置中:
watcher:
usePolling: true
https://github.com/brunch/brunch/blob/01afa693548d0dad2ade6528cedd20f0fbf8f2ac/docs/config.md#watcher
关于vagrant - 在 Vagrant/Virtualbox 中运行时,Brunch watch 不会处理后续更改的文件,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31119762/