Skip to content

Commit

Permalink
Allow the public path to be set for Webpack chunk loading. #182
Browse files Browse the repository at this point in the history
  • Loading branch information
paul121 authored and symbioquine committed Sep 28, 2022
1 parent 65f13b2 commit eedd137
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
<script type="text/javascript">
window.farmosMapPublicPath = '/libraries/farmOS-map';
</script>
<script src="./farmOS-map.js"></script>
```

## Upgrading from farmOS-map 1.x to 2.x

### For Authors of Custom Behaviors
Expand Down
2 changes: 2 additions & 0 deletions src/main.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Assign the public path before other imports.
import './publicPath';
import MapInstanceManager from './MapInstanceManager';

// Import the default projection configuration
Expand Down
5 changes: 5 additions & 0 deletions src/publicPath.js
Original file line number Diff line number Diff line change
@@ -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;
}

0 comments on commit eedd137

Please sign in to comment.