Skip to content

Commit

Permalink
support es2015
Browse files Browse the repository at this point in the history
  • Loading branch information
Bitaru committed Jan 13, 2023
1 parent 525b20e commit e17831c
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 7 deletions.
92 changes: 92 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<a name="readme-top"></a>

<div align="center">

<h3 align="center"><code>&#60;monaco-editor&#62;</code></h3>

<p align="center">
Monaco Editor as a web-component
<br />
<br />
<a href="https://github.com/othneildrew/Best-README-Template">View Demo</a>
·
<a href="https://github.com/Uscreen-video/monaco-component/issues">Report Bug</a>
</p>
</div>

## About

This is a minimal setup of [Monaco Editor](https://microsoft.github.io/monaco-editor/) in a shape of web-component. The main idea behind this repo is to skip building process of editor on the local environment.


<!-- GETTING STARTED -->
## Getting Started

### Prerequisites

To make it properly load from CDN you have to set a `window.__monaco_component_base` function that resolves a **url**

```javascript
window.__monaco_component_base = function(filename) {
return 'https://unpkg.com/monaco-component@latest/dist/' + filename
}
```

### Installation

Load from a CDN
```html
<script>
window.__monaco_component_base = function(filename) {
return 'https://unpkg.com/monaco-component@latest/dist/' + filename
}
</script>
<script type="module" src="https://unpkg.com/monaco-component@latest/lib/monaco-component.js"></script>
<script nomodule src="https://unpkg.com/monaco-component@latest/dist/index.js"></script>
```
Install using NPM packages
```sh
npm install monaco-component
```

<p align="right">(<a href="#readme-top">back to top</a>)</p>



<!-- USAGE EXAMPLES -->
## Usage

```html
<monaco-editor
value="<p>Hello world<p>"
name="test"
language="html"
theme="monokai"
></monaco-editor>
```
<p align="right">(<a href="#readme-top">back to top</a>)</p>

<!-- CONTRIBUTING -->
## Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are **greatly appreciated**.

If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement".
Don't forget to give the project a star! Thanks again!

1. Fork the Project
2. Create your Feature Branch (`git checkout -b feature/AmazingFeature`)
3. Commit your Changes (`git commit -m 'Add some AmazingFeature'`)
4. Push to the Branch (`git push origin feature/AmazingFeature`)
5. Open a Pull Request

<p align="right">(<a href="#readme-top">back to top</a>)</p>



<!-- LICENSE -->
## License

Distributed under the MIT License. See `LICENSE.txt` for more information.

<p align="right">(<a href="#readme-top">back to top</a>)</p>
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
<script type="module" src="/src/monaco-component.ts"></script>
</head>
<body>
<monaco-component></monaco-component>
<monaco-editor></monaco-editor>
</body>
</html>
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "monaco-component",
"version": "0.0.1",
"version": "0.0.2",
"description": "Monaco editor as web-component",
"type": "module",
"main": "lib/monaco-component.es.js",
Expand All @@ -15,7 +15,7 @@
],
"scripts": {
"dev": "vite",
"build": "tsc & vite build & vite build -c vite.lib.config.ts",
"build": "tsc && vite build && vite build -c vite.lib.config.ts",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [
Expand All @@ -24,6 +24,7 @@
"web-component"
],
"author": "Uscreen <[email protected]> (https://www.uscreen.tv)",
"homepage": "https://github.com/Uscreen-video/monaco-component#readme",
"license": "MIT",
"dependencies": {
"lit": "^2.6.1",
Expand Down
4 changes: 3 additions & 1 deletion vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ export default defineConfig({
}
}
},

build: {
target: 'es2015',
minify: 'terser',
rollupOptions: {
plugins: [
license({
Expand All @@ -32,3 +33,4 @@ export default defineConfig({
},
},
})

4 changes: 1 addition & 3 deletions vite.lib.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@ export default defineConfig({
experimental: {
renderBuiltUrl(filename: string, { hostType }: { hostType: 'js' | 'css' | 'html' }) {
if (hostType === 'js') {
return { runtime: `window.__monaco_component_base(${JSON.stringify(filename)})` }
return { runtime: `window.__monaco_component_module_base(${JSON.stringify(filename)})` }
} else {
return { relative: true }
}
}
},


build: {
rollupOptions: {
output: {
Expand Down

0 comments on commit e17831c

Please sign in to comment.