Class: KBuilder::Webpack5::WebpackBuilder
- Inherits:
-
BaseBuilder
- Object
- BaseBuilder
- KBuilder::Webpack5::WebpackBuilder
- Defined in:
- lib/k_builder/webpack5/webpack_builder.rb
Overview
Configuration currently comes from KBuilder and stores template folders and target folders if configured
Instance Attribute Summary collapse
-
#webpack_rc ⇒ Object
def webpack_config_file # Output Path may not be enough, I may need a webpack output path @webpack_config_file ||= File.join(target_folder, ‘webpack.config.js’) end.
Instance Method Summary collapse
- #entries(&block) ⇒ Object
- #entry(**entry_opts, &block) ⇒ Object
-
#initialize(configuration = nil) ⇒ WebpackBuilder
constructor
A new instance of WebpackBuilder.
- #mode(**mode_opts, &block) ⇒ Object
- #pause(seconds = 1) ⇒ Object
-
#plugin_mini_css_extract(**mini_css_extract_opts, &block) ⇒ Object
(also: #plugin_split_css)
Plugins.
-
#vscode ⇒ Object
Debug method to open the webpack_config file in vscode ToDo: Maybe remove.
- #webpack_dev_server(**dev_server_opts, &block) ⇒ Object
-
#webpack_init ⇒ Object
Webpack init will create .webconfig-rc.json.
- #webpack_rc_file ⇒ Object
Constructor Details
#initialize(configuration = nil) ⇒ WebpackBuilder
Returns a new instance of WebpackBuilder.
11 12 13 14 15 |
# File 'lib/k_builder/webpack5/webpack_builder.rb', line 11 def initialize(configuration = nil) super(configuration) @factory = KBuilder::Webpack5::WebpackJsonFactory end |
Instance Attribute Details
#webpack_rc ⇒ Object
def webpack_config_file
# Output Path may not be enough, I may need a webpack output path
@webpack_config_file ||= File.join(target_folder, 'webpack.config.js')
end
34 35 36 37 38 39 40 |
# File 'lib/k_builder/webpack5/webpack_builder.rb', line 34 def webpack_rc return @webpack_rc if defined? @webpack_rc load_webpack_rc @webpack_rc end |
Instance Method Details
#entries(&block) ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/k_builder/webpack5/webpack_builder.rb', line 102 def entries(&block) if @webpack_rc.entries.nil? @webpack_rc.entries = if block @factory.entries(&block) else entries_opts = { opinion: @factory.opinion_entries } @factory.entries(**entries_opts) end end write_webpack_rc self end |
#entry(**entry_opts, &block) ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/k_builder/webpack5/webpack_builder.rb', line 88 def entry(**entry_opts, &block) if @webpack_rc.entry.nil? @webpack_rc.entry = if block @factory.entry(&block) else entry_opts = { opinion: @factory.opinion_entry } if entry_opts.empty? @factory.entry(**entry_opts) end end write_webpack_rc self end |
#mode(**mode_opts, &block) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/k_builder/webpack5/webpack_builder.rb', line 74 def mode(**mode_opts, &block) if @webpack_rc.mode.nil? @webpack_rc.mode = if block @factory.mode(&block) else mode_opts = { opinion: @factory.opinion_mode } if mode_opts.empty? @factory.mode(**mode_opts) end end write_webpack_rc self end |
#pause(seconds = 1) ⇒ Object
163 164 165 166 167 |
# File 'lib/k_builder/webpack5/webpack_builder.rb', line 163 def pause(seconds = 1) sleep(seconds) self end |
#plugin_mini_css_extract(**mini_css_extract_opts, &block) ⇒ Object Also known as: plugin_split_css
Plugins
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/k_builder/webpack5/webpack_builder.rb', line 118 def plugin_mini_css_extract(**mini_css_extract_opts, &block) ensure_plugins if @webpack_rc.plugins.mini_css_extract.nil? @webpack_rc.plugins.mini_css_extract = if block @factory.mini_css_extract(&block) else mini_css_extract_opts = { opinion: @factory.opinion_mini_css_extract } if mini_css_extract_opts.empty? @factory.mini_css_extract(**mini_css_extract_opts) end @webpack_rc.root_scope.require_mini_css_extract_plugin = true end write_webpack_rc self end |
#vscode ⇒ Object
Debug method to open the webpack_config file in vscode ToDo: Maybe remove
155 156 157 158 159 160 161 |
# File 'lib/k_builder/webpack5/webpack_builder.rb', line 155 def vscode puts "cd #{target_folder}" puts webpack_rc_file rc "code #{webpack_rc_file}" self end |
#webpack_dev_server(**dev_server_opts, &block) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/k_builder/webpack5/webpack_builder.rb', line 60 def webpack_dev_server(**dev_server_opts, &block) if @webpack_rc.dev_server.nil? @webpack_rc.dev_server = if block @factory.dev_server(&block) else dev_server_opts = { opinion: @factory.opinion_dev_server } if dev_server_opts.empty? @factory.dev_server(**dev_server_opts) end end write_webpack_rc self end |
#webpack_init ⇒ Object
Webpack init will create .webconfig-rc.json
51 52 53 54 55 56 57 58 |
# File 'lib/k_builder/webpack5/webpack_builder.rb', line 51 def webpack_init File.delete(webpack_rc_file) if File.exist?(webpack_rc_file) @webpack_rc = @factory.webpack write_webpack_rc self end |
#webpack_rc_file ⇒ Object
42 43 44 |
# File 'lib/k_builder/webpack5/webpack_builder.rb', line 42 def webpack_rc_file @webpack_rc_file ||= File.join(target_folder, '.webpack-rc.json') end |