Skip to content
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

Allow the public path to be set for Webpack chunk loading #182

Merged
merged 1 commit into from
Sep 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}