mirror of
https://github.com/microsoft/monaco-editor.git
synced 2025-12-22 16:15:41 +01:00
Bundle AMD using requirejs
This commit is contained in:
parent
770b47221c
commit
db021c78d6
10 changed files with 116 additions and 8574 deletions
69
scripts/bundle.js
Normal file
69
scripts/bundle.js
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
const requirejs = require('requirejs');
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
const UglifyJS = require("uglify-js");
|
||||
const helpers = require('monaco-plugin-helpers');
|
||||
|
||||
const REPO_ROOT = path.resolve(__dirname, '..');
|
||||
|
||||
const sha1 = helpers.getGitVersion(REPO_ROOT);
|
||||
const semver = require('../package.json').version;
|
||||
const headerVersion = semver + '(' + sha1 + ')';
|
||||
|
||||
const BUNDLED_FILE_HEADER = [
|
||||
'/*!-----------------------------------------------------------------------------',
|
||||
' * Copyright (c) Microsoft Corporation. All rights reserved.',
|
||||
' * monaco-css version: ' + headerVersion,
|
||||
' * Released under the MIT license',
|
||||
' * https://github.com/Microsoft/monaco-css/blob/master/LICENSE.md',
|
||||
' *-----------------------------------------------------------------------------*/',
|
||||
''
|
||||
].join('\n');
|
||||
|
||||
bundleOne('monaco.contribution');
|
||||
bundleOne('cssMode');
|
||||
bundleOne('cssWorker');
|
||||
|
||||
function bundleOne(moduleId, exclude) {
|
||||
requirejs.optimize({
|
||||
baseUrl: 'out/amd/',
|
||||
name: 'vs/language/css/' + moduleId,
|
||||
out: 'release/dev/' + moduleId + '.js',
|
||||
exclude: exclude,
|
||||
paths: {
|
||||
'vs/language/css': REPO_ROOT + '/out/amd'
|
||||
},
|
||||
optimize: 'none',
|
||||
packages: [{
|
||||
name: 'vscode-css-languageservice',
|
||||
location: path.join(REPO_ROOT, 'node_modules/vscode-css-languageservice/lib/umd'),
|
||||
main: 'cssLanguageService'
|
||||
}, {
|
||||
name: 'vscode-languageserver-types',
|
||||
location: path.join(REPO_ROOT, 'node_modules/vscode-languageserver-types/lib/umd'),
|
||||
main: 'main'
|
||||
}, {
|
||||
name: 'vscode-uri',
|
||||
location: path.join(REPO_ROOT, 'node_modules/vscode-uri/lib/umd'),
|
||||
main: 'index'
|
||||
}, {
|
||||
name: 'vscode-nls',
|
||||
location: path.join(REPO_ROOT, '/out/amd/fillers'),
|
||||
main: 'vscode-nls'
|
||||
}]
|
||||
}, function (buildResponse) {
|
||||
const devFilePath = path.join(REPO_ROOT, 'release/dev/' + moduleId + '.js');
|
||||
const minFilePath = path.join(REPO_ROOT, 'release/min/' + moduleId + '.js');
|
||||
const fileContents = fs.readFileSync(devFilePath).toString();
|
||||
console.log();
|
||||
console.log(`Minifying ${devFilePath}...`);
|
||||
const result = UglifyJS.minify(fileContents, {
|
||||
output: {
|
||||
comments: 'some'
|
||||
}
|
||||
});
|
||||
console.log(`Done.`);
|
||||
try { fs.mkdirSync(path.join(REPO_ROOT, 'release/min')) } catch (err) { }
|
||||
fs.writeFileSync(minFilePath, BUNDLED_FILE_HEADER + result.code);
|
||||
})
|
||||
}
|
||||
|
|
@ -10,7 +10,7 @@ const REPO_ROOT = path.join(__dirname, '../');
|
|||
|
||||
helpers.packageESM({
|
||||
repoRoot: REPO_ROOT,
|
||||
esmSource: 'out',
|
||||
esmSource: 'out/esm',
|
||||
esmDestination: 'release/esm',
|
||||
entryPoints: [
|
||||
'monaco.contribution.js',
|
||||
|
|
@ -18,7 +18,7 @@ helpers.packageESM({
|
|||
'css.worker.js',
|
||||
],
|
||||
resolveAlias: {
|
||||
'vscode-nls': path.join(REPO_ROOT, "out/fillers/vscode-nls.js")
|
||||
'vscode-nls': path.join(REPO_ROOT, "out/esm/fillers/vscode-nls.js")
|
||||
},
|
||||
resolveSkip: [
|
||||
'monaco-editor-core'
|
||||
|
|
|
|||
|
|
@ -1,28 +0,0 @@
|
|||
const path = require('path');
|
||||
const webpack = require('webpack');
|
||||
|
||||
const REPO_ROOT = path.resolve(__dirname, '..');
|
||||
|
||||
exports.createWebpackConfig = function (isDev) {
|
||||
let targetFolder = isDev ? './release/dev' : './release/min';
|
||||
let mode = isDev ? 'development' : 'production';
|
||||
|
||||
return {
|
||||
entry: {
|
||||
"monaco.contribution": './release/esm/monaco.contribution',
|
||||
"cssMode": './release/esm/cssMode',
|
||||
"cssWorker": './release/esm/cssWorker'
|
||||
},
|
||||
output: {
|
||||
filename: '[name].js',
|
||||
path: path.resolve(REPO_ROOT, targetFolder),
|
||||
libraryTarget: "amd"
|
||||
},
|
||||
mode: mode,
|
||||
plugins: [
|
||||
new webpack.optimize.LimitChunkCountPlugin({
|
||||
maxChunks: 1,
|
||||
})
|
||||
],
|
||||
};
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue