add-default-options.js 1.6 KB

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