-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🙋: Ignore certain code sections #357
Comments
Sounds very much like an edge-case to me. You could achieve the same with a custom preprocessor. |
During html parsing, we could skip nodes that set the attribute That would be a decent design choice because we could extend it to |
@agauniyal here's a workaround for monaco (using cdn). Not pretty but gets around the conflict between the monaco loader's require and parcel's require. const cdnBase = 'https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.10.1/min';
fetch(`${cdnBase}/vs/loader.js`, { mode: 'cors' })
.then(response => response.text())
.then(text => {
const monacoLoader = {} as any;
window.monacoLoader = monacoLoader;
text = text
.replace(/var\s+_amdLoaderGlobal\s*=\s*this/, 'var _amdLoaderGlobal = window.monacoLoader')
.replace(/this\.isNode\s*=\s*e\.isNode/, 'this.isNode = false');
eval(text);
monacoLoader.require.config({ paths: { 'vs': `${cdnBase}/vs` } });
window.define = monacoLoader.define;
window.MonacoEnvironment = {
getWorkerUrl: () => URL.createObjectURL(new Blob([loaderProxyScript], { type: 'application/javascript' }))
};
monacoLoader.require(['vs/editor/editor.main'], () => {
const editor = monaco.editor.create(document.getElementById('container')!, {
value: [
'function x() {',
'\tconsole.log("Hello world!");',
'}'
].join('\n'),
language: 'javascript'
});
});
});
interface Window {
define: any;
monacoLoader: {
define: any;
require: any;
},
MonacoEnvironment: any;
}
const loaderProxyScript = `self.MonacoEnvironment = {
baseUrl: '${cdnBase}'
};
importScripts('${cdnBase}/vs/base/worker/workerMain.js');` |
@agauniyal I had the same problem, I'm also trying to use Monaco. Coincidentally, today they just fixed microsoft/monaco-editor#18 👍 |
I think I'm running into the same issue: I want to output an I end up with a compiled file where
and parcel's resolution of the The behaviour I want is for parcel to not reach into |
Monaco-Editor now supports Parcel, even with workers. See microsoft/vscode#46032 and microsoft/monaco-editor#774 |
@fathyb would you mind taking a look at my sample in https://github.com/Microsoft/monaco-editor-samples/blob/master/browser-esm-parcel/index.html - and letting me know if there is a better way to build and refer to the worker? |
@danmarshall it doesn't look like it's been released to npm yet. Any idea when the next release is? Once it gets released you could do (without the self.MonacoEnvironment = {
getWorker: function (moduleId, label) {
return new Worker('./node_modules/monaco-editor/esm/vs/editor/editor.worker')
}
} You can try it by applying the PR manually by overwriting import { globals } from '../common/platform.js';
import { logOnceWebWorkerWarning } from '../common/worker/simpleWorker.js';
function getWorker(workerId, label) {
// Option for hosts to overwrite the worker script (used in the standalone editor)
if (globals.MonacoEnvironment) {
if (typeof globals.MonacoEnvironment.getWorker === 'function') {
return globals.MonacoEnvironment.getWorker(workerId, label);
}
if (typeof globals.MonacoEnvironment.getWorkerUrl === 'function') {
return new Worker(globals.MonacoEnvironment.getWorkerUrl(workerId, label));
}
}
throw new Error(`You must define a function MonacoEnvironment.getWorkerUrl or MonacoEnvironment.getWorker`);
}
var WebWorker = /** @class */ (function () {
function WebWorker(moduleId, id, label, onMessageCallback, onErrorCallback) {
this.id = id;
this.worker = getWorker('workerMain.js', label);
|
I am also interested on this functionality. Regards |
🙋
Sometimes there are code portions that I don't want parcel to parse and completely ignore them while acting normally on rest of the file. An example is embedding monaco-editor where index.html code looks like -
🤔 Expected Behavior
Parcel should be able to ignore certain sections.
😯 Current Behavior
It'll try parsing the file but would not do it the right way so browser errors out. This is because monaco-editor has a long standing issue here - microsoft/monaco-editor#18 and I manually copy node_modules/monaco-editor to
public
directory in my build step.💁 Possible Solution
Use comments to inform parcel.js to ignore these sections(like eslint does)..
🔦 Context
Showstopper for me because I can't migrate to parcel.
🌍 Your Environment
The text was updated successfully, but these errors were encountered: