Class: Mxrb::Compiler::WebShellMaterializer
- Inherits:
-
Object
- Object
- Mxrb::Compiler::WebShellMaterializer
- Defined in:
- lib/mxrb/compiler/web_shell_materializer.rb
Overview
Completes web templates normally hydrated by Studio Pro's proprietary build stage.
Constant Summary collapse
- CACHE_REVISION =
rubocop:disable Metrics/ClassLength
6- PLACEHOLDER =
/\{\{[a-z0-9_-]+\}\}/i- DYNAMIC_PAGE_CACHE =
/ (?:\(0,[A-Za-z0-9$_.]+\)\(\))\.getConfig\("isDevModeEnabled"\)\?"": `\?\$\{((?:\(0,[A-Za-z0-9$_.]+\)\(\))\.getConfig\("cachebust"\))\}` /x- SELF_IMPORT =
%r{import\*as\s+(?<binding>[A-Za-z_$][A-Za-z0-9_$]*)\s+from"\./(?<asset>[A-Za-z0-9_.-]+\.js)"; e\.C\(\k<binding>\),}x
Instance Method Summary collapse
-
#initialize(web, version:) ⇒ WebShellMaterializer
constructor
A new instance of WebShellMaterializer.
- #materialize ⇒ Object
-
#materialize_dynamic_imports ⇒ Object
React Client deliberately omits page cache tokens in developer mode.
Constructor Details
#initialize(web, version:) ⇒ WebShellMaterializer
Returns a new instance of WebShellMaterializer.
19 20 21 22 |
# File 'lib/mxrb/compiler/web_shell_materializer.rb', line 19 def initialize(web, version:) @web = File.(web) @version = version.to_s end |
Instance Method Details
#materialize ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/mxrb/compiler/web_shell_materializer.rb', line 24 def materialize return 0 unless File.directory?(@web) changed = html_files.count { render_html(_1) } changed += materialize_dynamic_imports write_missing(File.join(@web, 'js', 'login_i18n.js'), login_i18n) write_missing(File.join(@web, 'lib', 'bootstrap', 'css', 'bootstrap.min.css'), login_styles) # React Client requests this conventional aggregate even when every widget # ships its styles through JavaScript or the compiled theme. write_missing(File.join(@web, 'dist', 'widgets.css'), '') changed end |
#materialize_dynamic_imports ⇒ Object
React Client deliberately omits page cache tokens in developer mode. Native mxrb rebuilds can then leave an already-open browser on an obsolete generated page.
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/mxrb/compiler/web_shell_materializer.rb', line 39 def materialize_dynamic_imports Dir.glob(File.join(@web, 'dist', '**', '*.js')).sort.count do |path| source = File.binread(path) rendered = render_javascript(source) next false if source == rendered write_versioned_chunk(path, rendered) true end end |