You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

21 lines
841 B

  1. // Dynamically set webpack's loading path depending on a meta header, in order
  2. // to share the same assets regardless of instance configuration.
  3. // See https://webpack.js.org/guides/public-path/#on-the-fly
  4. function removeOuterSlashes(string) {
  5. return string.replace(/^\/*/, '').replace(/\/*$/, '');
  6. }
  7. function formatPublicPath(host = '', path = '') {
  8. let formattedHost = removeOuterSlashes(host);
  9. if (formattedHost && !/^http/i.test(formattedHost)) {
  10. formattedHost = `//${formattedHost}`;
  11. }
  12. const formattedPath = removeOuterSlashes(path);
  13. return `${formattedHost}/${formattedPath}/`;
  14. }
  15. const cdnHost = document.querySelector('meta[name=cdn-host]');
  16. // eslint-disable-next-line camelcase, no-undef, no-unused-vars
  17. __webpack_public_path__ = formatPublicPath(cdnHost ? cdnHost.content : '', process.env.PUBLIC_OUTPUT_PATH);