Class: VueCli::Rails::Configuration
- Defined in:
- lib/vue_cli/rails/configuration.rb
Constant Summary collapse
- JS_CONFIG_CMD =
%{ node -e "console.log(JSON.stringify(require('./vue.rails.js').getSettings(), null, 2))" }.strip.freeze
Class Attribute Summary collapse
-
.dev_server_url ⇒ Object
readonly
Returns the value of attribute dev_server_url.
-
.entry_points ⇒ Object
readonly
Returns the value of attribute entry_points.
Class Method Summary collapse
Instance Method Summary collapse
- #[](path) ⇒ Object
- #dev_server_host ⇒ Object
- #entry_assets_dev(entry_point) ⇒ Object
- #entry_assets_prod(entry_point) ⇒ Object
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
- #load_config(config) ⇒ Object
- #node_env ⇒ Object
- #output_url_path ⇒ Object
- #to_json ⇒ Object
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
4 5 6 7 8 |
# File 'lib/vue_cli/rails/configuration.rb', line 4 def initialize @root = ::Rails.root load_config(YAML.load_file(@root.join('config/vue.yml'))) self.class.setup(self) end |
Class Attribute Details
.dev_server_url ⇒ Object (readonly)
Returns the value of attribute dev_server_url.
105 106 107 |
# File 'lib/vue_cli/rails/configuration.rb', line 105 def dev_server_url @dev_server_url end |
.entry_points ⇒ Object (readonly)
Returns the value of attribute entry_points.
105 106 107 |
# File 'lib/vue_cli/rails/configuration.rb', line 105 def entry_points @entry_points end |
Class Method Details
.check! ⇒ Object
107 108 109 110 111 112 113 114 115 |
# File 'lib/vue_cli/rails/configuration.rb', line 107 def check! return if ::Rails.root.join('config/vue.yml').exist? abort <<~ERROR [ERROR] Failed to load vue_cli-rails! Cannot find config file: config/vue.yml Please call below command to initialize Vue: #{::Rails.version.to_i > 4 ? 'rails' : 'bundle exec rake'} vue:create ERROR end |
.instance ⇒ Object
117 118 119 |
# File 'lib/vue_cli/rails/configuration.rb', line 117 def instance @instance ||= new end |
.setup(config) ⇒ Object
121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/vue_cli/rails/configuration.rb', line 121 def setup(config) config.dev_server_host.presence&.tap do |host| @dev_server_url = "http://#{host}/__manifest/" end @entry_points = {} manifest = config['manifestOutput'].presence manifest &&= Pathname.new(manifest) if manifest&.exist? @entry_points = (JSON.parse(manifest.read || '{}')['entrypoints'] || {}).freeze end end |
Instance Method Details
#[](path) ⇒ Object
87 88 89 |
# File 'lib/vue_cli/rails/configuration.rb', line 87 def [](path) @config[path] end |
#dev_server_host ⇒ Object
95 96 97 98 |
# File 'lib/vue_cli/rails/configuration.rb', line 95 def dev_server_host dev_server = @config['devServer'] dev_server ? "#{dev_server['host'] || localhost}:#{dev_server['port'] || 8080}" : nil end |
#entry_assets_dev(entry_point) ⇒ Object
14 15 16 17 |
# File 'lib/vue_cli/rails/configuration.rb', line 14 def entry_assets_dev(entry_point) assets = Net::HTTP.get(URI("#{self.class.dev_server_url}?#{entry_point}")) assets.blank? ? nil : JSON.parse(assets) end |
#entry_assets_prod(entry_point) ⇒ Object
10 11 12 |
# File 'lib/vue_cli/rails/configuration.rb', line 10 def entry_assets_prod(entry_point) self.class.entry_points[entry_point] end |
#load_config(config) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/vue_cli/rails/configuration.rb', line 31 def load_config(config) config = config[::Rails.env] entry_path = config['entry_path'].presence || 'app/assets/vue/entry_points' c = { 'configureWebpack' => { 'entry' => entry(entry_path), 'resolve' => {}, }, } @package_manager = config['package_manager'] cw = c['configureWebpack'] c['env'] = ::Rails.env c['root'] = @root.to_s cw['output'] = config['js_output'] if config['js_output'].present? c['manifestOutput'] = config['manifest_output'] public_output_path = c['public_output_path'] || 'vue_assets' c['outputDir'] = File.join(resolve('public'), public_output_path) c['publicPath'] = File.join('/', public_output_path, '/') %w[ launch_node modern filenameHashing lintOnSave runtimeCompiler transpileDependencies productionSourceMap crossorigin css devServer parallel pwa pluginOptions ].each { |k| c[k] = config[k] if config.key?(k) } jest = {} c['jestModuleNameMapper'] = jest resolve_config(c, 'manifestOutput') if c['manifestOutput'].present? config['alias']&.tap do |aliases| aliases.each_key do |k| key = k.gsub(%r<(?=[-{}()+.,^$#/\s\]])>, '\\') path = aliases[k].sub(%r/^\//, '').sub(%r/\/$/, '') jest["^#{key}/(.*)$"] = "<rootDir>/#{path}/$1" resolve_config(aliases, k) end cw['resolve']['alias'] = aliases end dev_server = c['devServer'] || {} resolve_config(dev_server, 'contentBase') ensure @config = c end |
#node_env ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/vue_cli/rails/configuration.rb', line 19 def node_env raise(Error, 'Incorrect package_manager in config/vue.yml') if @package_manager.blank? @node_env ||= NodeEnv.new do |ne| ne.use!(@package_manager) end end |
#output_url_path ⇒ Object
91 92 93 |
# File 'lib/vue_cli/rails/configuration.rb', line 91 def output_url_path @config['publicPath'] end |
#to_json ⇒ Object
100 101 102 |
# File 'lib/vue_cli/rails/configuration.rb', line 100 def to_json JSON.pretty_generate(@config) end |