mirror of
https://github.com/microsoft/monaco-editor.git
synced 2025-12-22 19:42:56 +01:00
Fixes #42: Handle cross origin web workers automatically
This commit is contained in:
parent
f6223d69e6
commit
802217b877
3 changed files with 35 additions and 1 deletions
|
|
@ -6,6 +6,7 @@
|
||||||
"typings": "./out/index.d.ts",
|
"typings": "./out/index.d.ts",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "node ./node_modules/webpack/bin/webpack.js --config test/webpack.config.js",
|
"test": "node ./node_modules/webpack/bin/webpack.js --config test/webpack.config.js",
|
||||||
|
"test-cross-origin": "node ./node_modules/webpack/bin/webpack.js --config test/webpack-cross-origin.config.js",
|
||||||
"watch": "tsc -w -p tsconfig.json",
|
"watch": "tsc -w -p tsconfig.json",
|
||||||
"prepublishOnly": "tsc -p tsconfig.json"
|
"prepublishOnly": "tsc -p tsconfig.json"
|
||||||
},
|
},
|
||||||
|
|
|
||||||
11
src/index.ts
11
src/index.ts
|
|
@ -190,7 +190,16 @@ function createLoaderRules(languages: IFeatureDefinition[], features: IFeatureDe
|
||||||
return {
|
return {
|
||||||
getWorkerUrl: function (moduleId, label) {
|
getWorkerUrl: function (moduleId, label) {
|
||||||
var pathPrefix = ${pathPrefix};
|
var pathPrefix = ${pathPrefix};
|
||||||
return (pathPrefix ? stripTrailingSlash(pathPrefix) + '/' : '') + paths[label];
|
var result = (pathPrefix ? stripTrailingSlash(pathPrefix) + '/' : '') + paths[label];
|
||||||
|
if (/^(http:)|(https:)|(file:)/.test(result)) {
|
||||||
|
var currentUrl = String(window.location);
|
||||||
|
var currentOrigin = currentUrl.substr(0, currentUrl.length - window.location.hash.length - window.location.search.length - window.location.pathname.length);
|
||||||
|
if (result.substring(0, currentOrigin.length) !== currentOrigin) {
|
||||||
|
var js = '/*' + label + '*/importScripts("' + result + '");';
|
||||||
|
return 'data:text/javascript;charset=utf-8,' + encodeURIComponent(js);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
})(${JSON.stringify(workerPaths, null, 2)})`,
|
})(${JSON.stringify(workerPaths, null, 2)})`,
|
||||||
|
|
|
||||||
24
test/webpack-cross-origin.config.js
Normal file
24
test/webpack-cross-origin.config.js
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
const MonacoWebpackPlugin = require('../out/index.js');
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
|
const ASSET_PATH = 'http://localhost:8088/monaco-editor-webpack-plugin/test/dist/';
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
mode: 'development',
|
||||||
|
entry: './index.js',
|
||||||
|
context: __dirname,
|
||||||
|
output: {
|
||||||
|
path: path.resolve(__dirname, 'dist'),
|
||||||
|
filename: 'app.js',
|
||||||
|
publicPath: ASSET_PATH
|
||||||
|
},
|
||||||
|
module: {
|
||||||
|
rules: [{
|
||||||
|
test: /\.css$/,
|
||||||
|
use: ['style-loader', 'css-loader']
|
||||||
|
}]
|
||||||
|
},
|
||||||
|
plugins: [
|
||||||
|
new MonacoWebpackPlugin()
|
||||||
|
]
|
||||||
|
};
|
||||||
Loading…
Add table
Add a link
Reference in a new issue