mirror of
https://github.com/microsoft/monaco-editor.git
synced 2025-12-22 08:10:11 +01:00
repairs esm and amd build (#4950)
This commit is contained in:
parent
f420968fc9
commit
e56ad4b588
43 changed files with 2302 additions and 856 deletions
7
build/amd/build.script.ts
Normal file
7
build/amd/build.script.ts
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
import { run } from '../../scripts/lib/index';
|
||||
|
||||
export async function buildAmdMinDev() {
|
||||
const rootPath = __dirname;
|
||||
await run('npx vite build --mode development', { cwd: rootPath });
|
||||
await run('npx vite build', { cwd: rootPath });
|
||||
}
|
||||
44
build/amd/src/editor.main.js
Normal file
44
build/amd/src/editor.main.js
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
self.MonacoEnvironment = {
|
||||
getWorker: function (_moduleId, label) {
|
||||
if (label === 'json') {
|
||||
return new Worker(new URL('../../../src/language/json/json.worker.ts', import.meta.url), {
|
||||
type: 'module'
|
||||
});
|
||||
}
|
||||
if (label === 'css' || label === 'scss' || label === 'less') {
|
||||
return new Worker(new URL('../../../src/language/css/css.worker.ts', import.meta.url), {
|
||||
type: 'module'
|
||||
});
|
||||
}
|
||||
if (label === 'html' || label === 'handlebars' || label === 'razor') {
|
||||
return new Worker(new URL('../../../src/language/html/html.worker.ts', import.meta.url), {
|
||||
type: 'module'
|
||||
});
|
||||
}
|
||||
if (label === 'typescript' || label === 'javascript') {
|
||||
return new Worker(new URL('../../../src/language/typescript/ts.worker.ts', import.meta.url), {
|
||||
type: 'module'
|
||||
});
|
||||
}
|
||||
return new Worker(new URL('../../../src/editor/editor.worker.ts', import.meta.url), {
|
||||
type: 'module'
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
import 'vs/nls.messages-loader!';
|
||||
import '../../../src/basic-languages/monaco.contribution';
|
||||
import '../../../src/language/css/monaco.contribution';
|
||||
import '../../../src/language/html/monaco.contribution';
|
||||
import '../../../src/language/json/monaco.contribution';
|
||||
import '../../../src/language/typescript/monaco.contribution';
|
||||
import * as require_ from 'require';
|
||||
|
||||
const styleSheetUrl = require_.toUrl('vs/style.css');
|
||||
|
||||
const link = document.createElement('link');
|
||||
link.rel = 'stylesheet';
|
||||
link.href = styleSheetUrl;
|
||||
document.head.appendChild(link);
|
||||
|
||||
export * as m from 'monaco-editor-core';
|
||||
1368
build/amd/src/loader.js
Normal file
1368
build/amd/src/loader.js
Normal file
File diff suppressed because it is too large
Load diff
10
build/amd/src/nls.messages-loader.js
Normal file
10
build/amd/src/nls.messages-loader.js
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
export function load(name, req, load, config) {
|
||||
const requestedLanguage = config['vs/nls']?.availableLanguages?.['*'];
|
||||
if (!requestedLanguage || requestedLanguage === 'en') {
|
||||
load({});
|
||||
} else {
|
||||
req([`vs/nls.messages.${requestedLanguage}`], () => {
|
||||
load({});
|
||||
});
|
||||
}
|
||||
}
|
||||
79
build/amd/vite.config.js
Normal file
79
build/amd/vite.config.js
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
import { readFileSync } from 'node:fs';
|
||||
import { glob } from 'node:fs/promises';
|
||||
import { basename, dirname, join, resolve } from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { defineConfig } from 'vite';
|
||||
|
||||
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||
|
||||
export default defineConfig(async (args) => {
|
||||
const monacoEditorCoreDir = join(
|
||||
dirname(require.resolve('monaco-editor-core/package.json')),
|
||||
'esm'
|
||||
);
|
||||
const nlsEntries = {};
|
||||
for await (const path of glob(`${monacoEditorCoreDir}/nls.messages.*.js`)) {
|
||||
const entryName = basename(path).replace('.js', '');
|
||||
nlsEntries[entryName] = path;
|
||||
}
|
||||
|
||||
return {
|
||||
base: './',
|
||||
define: {
|
||||
AMD: false
|
||||
},
|
||||
build: {
|
||||
lib: {
|
||||
entry: {
|
||||
...nlsEntries,
|
||||
'nls.messages-loader': resolve(__dirname, 'src/nls.messages-loader.js'),
|
||||
'editor/editor.main': resolve(__dirname, 'src/editor.main.js'),
|
||||
'language/css/monaco.contribution': resolve(
|
||||
__dirname,
|
||||
'../../src/language/css/monaco.contribution.ts'
|
||||
),
|
||||
'language/html/monaco.contribution': resolve(
|
||||
__dirname,
|
||||
'../../src/language/html/monaco.contribution.ts'
|
||||
),
|
||||
'language/json/monaco.contribution': resolve(
|
||||
__dirname,
|
||||
'../../src/language/json/monaco.contribution.ts'
|
||||
),
|
||||
'language/typescript/monaco.contribution': resolve(
|
||||
__dirname,
|
||||
'../../src/language/typescript/monaco.contribution.ts'
|
||||
)
|
||||
},
|
||||
name: 'monaco-editor',
|
||||
fileName: (_format, entryName) => entryName + '.js',
|
||||
formats: ['amd']
|
||||
},
|
||||
outDir: resolve(
|
||||
__dirname,
|
||||
'../../out/monaco-editor/',
|
||||
args.mode === 'development' ? 'dev' : 'min',
|
||||
'vs'
|
||||
),
|
||||
rollupOptions: {
|
||||
external: ['require', 'vs/nls.messages-loader!'],
|
||||
output: {}
|
||||
},
|
||||
minify: args.mode !== 'development',
|
||||
emptyOutDir: true
|
||||
},
|
||||
plugins: [
|
||||
{
|
||||
name: 'copy-loader',
|
||||
apply: 'build',
|
||||
generateBundle() {
|
||||
this.emitFile({
|
||||
type: 'asset',
|
||||
fileName: 'loader.js',
|
||||
source: readFileSync(resolve(__dirname, './src/loader.js'), 'utf-8')
|
||||
});
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue