-
Notifications
You must be signed in to change notification settings - Fork 1k
Fixes #37102 - webpack 5 #9834
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes #37102 - webpack 5 #9834
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,7 @@ | ||
| # Run Rails & Webpack concurrently | ||
| # If you wish to use a different server then the default, use e.g. `export RAILS_STARTUP='puma -w 3 -p 3000 --preload'` | ||
| rails: [ -n "$RAILS_STARTUP" ] && env PRY_WARNING=1 $RAILS_STARTUP || [ -n "$BIND" ] && bin/rails server -b $BIND || env PRY_WARNING=1 bin/rails server | ||
| # you can use WEBPACK_OPTS to customize webpack server, e.g. 'WEBPACK_OPTS='--https --key /path/to/key --cert /path/to/cert.pem --cacert /path/to/cacert.pem' foreman start ' | ||
| webpack: [ -n "$NODE_ENV" ] && ./node_modules/.bin/webpack-dev-server-without-h2 --config config/webpack.config.js $WEBPACK_OPTS || env NODE_ENV=development ./node_modules/.bin/webpack-dev-server-without-h2 --config config/webpack.config.js $WEBPACK_OPTS | ||
|
|
||
| # you can use WEBPACK_OPTS to customize webpack server, e.g. 'WEBPACK_OPTS=--progress' foreman start ' | ||
| # filter out webpack options that are commonly used but not supported by webpack 5 and not needed in the new configutation as webpack is not run as a server anymore | ||
| webpack: FILTERED_WEBPACK_OPTS=$(echo $WEBPACK_OPTS | sed -e 's/--key [^ ]*//g' -e 's/--public [^ ]*//g' -e 's/--https [^ ]*//g' -e 's/--cert [^ ]*//g' -e 's/--cacert [^ ]*//g') && [ -n "$NODE_ENV" ] && npx webpack --config config/webpack.config.js --watch $FILTERED_WEBPACK_OPTS || env NODE_ENV=development npx webpack --config config/webpack.config.js --watch $FILTERED_WEBPACK_OPTS |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| function load_dynamic_javascripts(html) { | ||
| function waitForAllLoaded() { | ||
| // Wait for all plugins js modules to be loaded before loading the javascript content | ||
| return new Promise(function(resolve) { | ||
| // window.allPluginsLoaded is set to {} when plugins are starting to load | ||
| // if there are no plugins window.allPluginsLoaded is never defined | ||
| if (window.allPluginsLoaded === undefined || Object.values(window.allPluginsLoaded).every(Boolean)) { | ||
| resolve(); | ||
| } else { | ||
| function handleLoad() { | ||
| if (window.allPluginsLoaded === undefined || Object.values(window.allPluginsLoaded).every(Boolean)) { | ||
| resolve(); | ||
| // Remove the event listener | ||
| document.removeEventListener('loadPlugin', handleLoad); | ||
| } | ||
| } | ||
| document.addEventListener('loadPlugin', handleLoad); | ||
| } | ||
| }); | ||
| } | ||
| waitForAllLoaded().then(async function() { | ||
| // parse html string | ||
| var template = document.createElement('template'); | ||
| template.innerHTML = html; | ||
| var doc = new DOMParser().parseFromString(html, 'text/html'); | ||
| var copyChildren = [...doc.head.children]; | ||
| const loadScript = async scripts => { | ||
| if (scripts.length === 0) { | ||
| // All scripts are loaded | ||
| window.allJsLoaded = true; | ||
| const loadJS = new Event('loadJS'); | ||
| document.dispatchEvent(loadJS); | ||
| return; | ||
| } | ||
| const script = scripts.shift(); | ||
| if (script.src) { | ||
| // if script is just a link, add it to the head | ||
| const scriptTag = document.createElement('script'); | ||
| scriptTag.src = script.src; | ||
| scriptTag.onload = function() { | ||
| // To load the next script only after the current one is loaded | ||
| loadScript(scripts); | ||
| }; | ||
| document.head.appendChild(scriptTag); | ||
| } else { | ||
| // if the script is a script tag, evaluate it and load the next one | ||
| await eval(script.innerHTML); | ||
| loadScript(scripts); | ||
| } | ||
| }; | ||
| loadScript(copyChildren); | ||
| }); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -99,6 +99,29 @@ def javascript(*args) | |
| content_for(:javascripts) { javascript_include_tag(*args) } | ||
| end | ||
|
|
||
| def javascript_include_tag(*params, **kwargs) | ||
| # Workaround for overriding javascript load with webpack_asset_paths, should be removed when webpack_asset_paths is removed | ||
| if kwargs[:source] == "webpack_asset_paths" | ||
| kwargs[:webpacked] | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's no
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we dont want to call super cause it returns a script tag, |
||
| else | ||
| super(*params, **kwargs) | ||
| end | ||
| end | ||
|
|
||
| # @deprecated Previously provided by webpack-rails | ||
| def webpack_asset_paths(plugin_name, extension: 'js') | ||
|
MariaAga marked this conversation as resolved.
Outdated
|
||
| if extension == 'js' | ||
| Foreman::Deprecation.deprecation_warning('3.12', '`webpack_asset_paths` is deprecated, use `content_for(:javascripts) { webpacked_plugins_js_for(plugin_name) }` instead.') | ||
| [{ | ||
| source: 'webpack_asset_paths', | ||
| webpacked: webpacked_plugins_js_for(plugin_name.to_sym), | ||
| }] | ||
| elsif extension == 'css' | ||
| Foreman::Deprecation.deprecation_warning('3.12', '`webpack_asset_paths` is deprecated and not needed for css assets.') | ||
| nil | ||
| end | ||
| end | ||
|
|
||
| # The target should have class="collapse [out|in]" out means collapsed on load and in means expanded. | ||
| # Target must also have a unique id. | ||
| def collapsing_header(title, target, collapsed = '') | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.