add-default-options.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import {addDataAttr} from './utils.js';
  2. import browser from './browser.js';
  3. /**
  4. * @param {Window} window
  5. * @param {Record<string, *>} options
  6. */
  7. export default (window, options) => {
  8. // use options from the current script tag data attribues
  9. addDataAttr(options, browser.currentScript(window));
  10. if (options.isFileProtocol === undefined) {
  11. options.isFileProtocol = /^(file|(chrome|safari)(-extension)?|resource|qrc|app):/.test(window.location.protocol);
  12. }
  13. // Load styles asynchronously (default: false)
  14. //
  15. // This is set to `false` by default, so that the body
  16. // doesn't start loading before the stylesheets are parsed.
  17. // Setting this to `true` can result in flickering.
  18. //
  19. options.async = options.async || false;
  20. options.fileAsync = options.fileAsync || false;
  21. // Interval between watch polls
  22. options.poll = options.poll || (options.isFileProtocol ? 1000 : 1500);
  23. options.env = options.env || (window.location.hostname == '127.0.0.1' ||
  24. window.location.hostname == '0.0.0.0' ||
  25. window.location.hostname == 'localhost' ||
  26. (window.location.port &&
  27. window.location.port.length > 0) ||
  28. options.isFileProtocol ? 'development'
  29. : 'production');
  30. const dumpLineNumbers = /!dumpLineNumbers:(comments|mediaquery|all)/.exec(window.location.hash);
  31. if (dumpLineNumbers) {
  32. options.dumpLineNumbers = dumpLineNumbers[1];
  33. }
  34. if (options.useFileCache === undefined) {
  35. options.useFileCache = true;
  36. }
  37. if (options.onReady === undefined) {
  38. options.onReady = true;
  39. }
  40. if (options.relativeUrls) {
  41. options.rewriteUrls = 'all';
  42. }
  43. };