diff --git a/CHANGELOG.md b/CHANGELOG.md index c614240..44c4139 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Changed + +- Allow the public path to be set for Webpack chunk loading. #182 + ## [v2.0.7] - 2022-09-22 ### Fixed diff --git a/README.md b/README.md index fdb47c2..dd98074 100644 --- a/README.md +++ b/README.md @@ -647,6 +647,23 @@ farmOS-map will be accessed at `window.farmOS.map`. Naturally, this requires tha and `farmOS-map.css` files are already included in the page as described in the [Usage instructions](#usage) above. +### Webpack chunk loading + +farmOS-map is bundled using Webpack's [Automatic Public Path](https://webpack.js.org/guides/public-path/#automatic-publicpath) +configuration to automatically determine the public path used for chunk loading. +This configuration works most of the time but advanced integrations may need to +specify a public path for consistent chunk loading [on the fly](https://webpack.js.org/guides/public-path/#on-the-fly). + +The public path can be specified by setting `window.farmosMapPublicPath` before +the `farmOS-map.js` entrypoint is loaded in the DOM. For example: + +```html + + +``` + ## Upgrading from farmOS-map 1.x to 2.x ### For Authors of Custom Behaviors diff --git a/src/main.js b/src/main.js index 7ea645b..b3148df 100644 --- a/src/main.js +++ b/src/main.js @@ -1,3 +1,5 @@ +// Assign the public path before other imports. +import './publicPath'; import MapInstanceManager from './MapInstanceManager'; // Import the default projection configuration diff --git a/src/publicPath.js b/src/publicPath.js new file mode 100644 index 0000000..b304879 --- /dev/null +++ b/src/publicPath.js @@ -0,0 +1,5 @@ +// Allow the public path to be set for Webpack chunk loading. +if (typeof window.farmosMapPublicPath !== 'undefined') { + // eslint-disable-next-line camelcase, no-undef + __webpack_public_path__ = window.farmosMapPublicPath; +}