该项目使用的是Ruby Webpacker,Lando用于本地开发。 我的config/webpacker.yml
包含以下内容:
development:
<<: *default
compile: true
dev_server:
public: some.lndo.site
host: '0.0.0.0'
port: 3035
...
watch_options:
poll: 1000
aggregate_timeout: 500
因此,在webpacker.yml
为我的本地环境添加/编辑参数的插入,我可以将其中一些选项设置为.lando.yml
文件中的环境变量(即public
,host
,port
(:
services:
appserver:
type: ruby:2.6.3
overrides:
environment:
WEBPACKER_DEV_SERVER_PUBLIC: some.lndo.site
WEBPACKER_DEV_SERVER_HOST: '0.0.0.0'
WEBPACKER_DEV_SERVER_PORT: '3035'
...
这行得通。
问题:但是我怎样才能为watch-options
设置环境变量(即poll
( 通过环境变量?
我试过这些,但没有运气:
WEBPACKER_DEV_SERVER_WATCHOPTIONS_POLL
WEBPACKER_DEV_SERVER_WATCH_OPTIONS_POLL
WEBPACKER_DEV_SERVER_POLL
看起来目前不支持dev_server
对象中的嵌套 JSON(从 Webpacker v4.2.0 开始(,其中在ENV["WEBPACK_DEV_SERVER_#{key.upcase}"]
中插值的key
仅与顶级键匹配:https://github.com/rails/webpacker/blob/417542c8ed7d344ecc24b3ae40e303d478ad50d0/lib/webpacker/dev_server.rb#L59-L61
# env_prefix = "WEBPACKER_DEV_SERVER".freeze
def fetch(key)
ENV["#{env_prefix}_#{key.upcase}"] || config.dev_server.fetch(key, defaults[key])
end
由于我猜您不需要 Rails 服务器来了解监视轮询选项,因此没有必要将动态值传递给config/webpacker.yml
。相反,我会用config/webpack/development.js
来阅读它们,即直接在 Webpack 中阅读:
// config/webpack/development.js
const environment = require('./environment.js');
environment.config.merge({
devServer: {
watchOptions: {
poll: process.env.WEBPACK_DEV_SERVER_WATCH_POLL,
aggregateTimeout: process.env.WEBPACK_DEV_SERVER_WATCH_TIMEOUT
}
}
});
module.exports = environment.toWebpackConfig();