Fix worker cross domain issue

This commit is contained in:
Jerome Wu
2019-10-30 21:23:51 +08:00
parent f517504c71
commit 0455923e43
6 changed files with 43 additions and 5 deletions

View File

@@ -0,0 +1,10 @@
module.exports = (key) => {
const env = {
type: (typeof window !== 'undefined') && (typeof window.document !== 'undefined') ? 'browser' : 'node',
};
if (typeof key === 'undefined') {
return env;
}
return env[key];
};

12
src/utils/resolvePaths.js Normal file
View File

@@ -0,0 +1,12 @@
const isBrowser = require('./getEnvironment')('type') === 'browser';
const resolveURL = isBrowser ? require('resolve-url') : s => s; // eslint-disable-line
module.exports = (options) => {
const opts = { ...options };
['corePath', 'workerPath'].forEach((key) => {
if (typeof options[key] !== 'undefined') {
opts[key] = resolveURL(opts[key]);
}
});
return opts;
};