mirror of
https://github.com/microsoft/monaco-editor.git
synced 2025-12-22 19:42:56 +01:00
Adding examples
Adding an example with the monaco webpack plugin
This commit is contained in:
parent
3ec5c9d2e3
commit
27b10e31fa
5 changed files with 6330 additions and 0 deletions
30
browser-esm-webpack-monaco-plugin/index.html
Normal file
30
browser-esm-webpack-monaco-plugin/index.html
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h2>Monaco Editor Webpack Plugin Sample</h2>
|
||||
|
||||
To run this sample, you need to:
|
||||
|
||||
<pre>
|
||||
$/browser-esm-webpack-monaco-plugin> npm install
|
||||
$/browser-esm-webpack-monaco-plugin> npm run start
|
||||
|
||||
# or to build for production
|
||||
$/browser-esm-webpack-monaco-plugin> npm run build
|
||||
</pre>
|
||||
|
||||
If you're building for production you need to statically serve the files:
|
||||
|
||||
<pre>
|
||||
$/browser-esm-webpack-monaco-plugin> npm run build
|
||||
$/browser-esm-webpack-monaco-plugin> cd dist
|
||||
$/browser-esm-webpack-monaco-plugin/dist> npx static-server -p 3000 -o
|
||||
</pre>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
20
browser-esm-webpack-monaco-plugin/index.js
Normal file
20
browser-esm-webpack-monaco-plugin/index.js
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
import * as monaco from "monaco-editor";
|
||||
|
||||
(function () {
|
||||
// create div to avoid needing a HtmlWebpackPlugin template
|
||||
const div = document.createElement('div');
|
||||
div.id = 'root';
|
||||
div.style = 'width:800px; height:600px; border:1px solid #ccc;';
|
||||
|
||||
document.body.appendChild(div);
|
||||
})();
|
||||
|
||||
monaco.editor.create(
|
||||
document.getElementById('root'),
|
||||
{
|
||||
value: `const foo = () => 0;`,
|
||||
language: 'javascript',
|
||||
theme: 'vs-dark'
|
||||
}
|
||||
);
|
||||
|
||||
6209
browser-esm-webpack-monaco-plugin/package-lock.json
generated
Normal file
6209
browser-esm-webpack-monaco-plugin/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load diff
28
browser-esm-webpack-monaco-plugin/package.json
Normal file
28
browser-esm-webpack-monaco-plugin/package.json
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
{
|
||||
"name": "monaco",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"start": "webpack-dev-server --progress --mode development",
|
||||
"build": "webpack --progress --mode production"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"devDependencies": {
|
||||
"css-loader": "^2.1.1",
|
||||
"file-loader": "^3.0.1",
|
||||
"html-webpack-plugin": "^3.2.0",
|
||||
"monaco-editor-webpack-plugin": "^1.7.0",
|
||||
"style-loader": "^0.23.1",
|
||||
"webpack": "^4.32.0",
|
||||
"webpack-cli": "^3.3.2",
|
||||
"webpack-dev-server": "^3.4.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"monaco-editor": "^0.16.2"
|
||||
}
|
||||
}
|
||||
43
browser-esm-webpack-monaco-plugin/webpack.config.js
Normal file
43
browser-esm-webpack-monaco-plugin/webpack.config.js
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
const path = require("path");
|
||||
const MonacoWebpackPlugin = require("monaco-editor-webpack-plugin");
|
||||
const HtmlWebpackPlugin = require("html-webpack-plugin");
|
||||
|
||||
module.exports = {
|
||||
mode: process.env.NODE_ENV,
|
||||
entry: "./index.js",
|
||||
output: {
|
||||
path: path.resolve(__dirname, "dist"),
|
||||
filename: "[name].bundle.js",
|
||||
},
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
test: /\.css$/,
|
||||
use: [
|
||||
"style-loader",
|
||||
"css-loader",
|
||||
],
|
||||
},
|
||||
{
|
||||
test: /\.(png|jpg|gif|svg|woff2?|ttf|eot|otf)$/,
|
||||
use: [
|
||||
{
|
||||
loader: "file-loader",
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
plugins: [
|
||||
new MonacoWebpackPlugin({
|
||||
languages: ["typescript", "javascript", "css"],
|
||||
}),
|
||||
new HtmlWebpackPlugin()
|
||||
],
|
||||
devServer: {
|
||||
port: 4000,
|
||||
hot: process.env.NODE_ENV === 'development',
|
||||
open: true
|
||||
},
|
||||
devtool: process.argv.includes("--use-sourcemaps") ? "inline-source-map" : false,
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue