Skip to content

Commit

Permalink
fix(vue-playground): build error, remove monaco workers
Browse files Browse the repository at this point in the history
  • Loading branch information
2214962083 committed May 10, 2022
1 parent 1707879 commit ad261f8
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export const getOutputMap = (minify: boolean): Record<LibraryFormats, string> =>
export interface CreateViteConfigOptions {
minify?: boolean
packagePath: string
formats?: LibraryFormats[]
externalMap?: Record<string, string>
dedupe?: string[] // use the same version
plugins?: PluginOption[]
Expand All @@ -33,13 +34,17 @@ export const createViteConfig = (options: CreateViteConfigOptions): UserConfig =
const {
minify = false,
packagePath,
formats = ['es', 'cjs', 'umd', 'iife'],
externalMap = {},
dedupe: _dedupe = [],
plugins = [],
alias: _alias = [],
test
} = options
const outputMap = getOutputMap(minify)

const outputMap = Object.fromEntries(
Object.entries(getOutputMap(minify)).filter(([format]) => formats.includes(format as LibraryFormats))
) as Record<LibraryFormats, string>

const pathResolve = (..._path: string[]) => path.resolve(packagePath, ..._path)

Expand Down Expand Up @@ -88,7 +93,10 @@ export const createViteConfig = (options: CreateViteConfigOptions): UserConfig =
},
rollupOptions: {
output: {
globals: externalMap
globals: externalMap,
chunkFileNames: () => {
return '[format]/[name].[format].js'
}
},
external: Object.keys(externalMap)
},
Expand Down
12 changes: 7 additions & 5 deletions packages/vue-playground/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
"main": "./dist/index.cjs",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"unpkg": "./dist/index.min.umd.js",
"jsdelivr": "./dist/index.min.umd.js",
"unpkg": "/dist/index.min.mjs",
"jsdelivr": "/dist/index.min.mjs",
"exports": {
".": {
"require": "./dist/index.cjs",
Expand All @@ -52,7 +52,8 @@
},
"homepage": "https://github.com/2214962083/vue-superman#readme",
"peerDependencies": {
"vue": "^3.2.0"
"vue": ">=3.0.0",
"monaco-editor": ">=0.30.0"
},
"dependencies": {
"@babel/types": "^7.17.10",
Expand All @@ -63,9 +64,9 @@
"@vueuse/core": "^8.4.1",
"emmet-monaco-es": "^5.1.0",
"js-base64": "^3.7.2",
"monaco-editor": "^0.33.0",
"sucrase": "^3.21.0",
"theme-vitesse": "^0.4.9"
"theme-vitesse": "^0.4.9",
"vue-demi": "*"
},
"devDependencies": {
"@types/node": "^17.0.24",
Expand All @@ -77,6 +78,7 @@
"cross-env": "^7.0.3",
"esno": "^0.14.1",
"jsdom": "^19.0.0",
"monaco-editor": "^0.33.0",
"rimraf": "^3.0.2",
"superman-shared": "workspace:*",
"typescript": "4.6.3",
Expand Down
9 changes: 0 additions & 9 deletions packages/vue-playground/scripts/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,6 @@ import {buildUtils} from 'superman-shared'
import {minifyConfig, unMinifyConfig, packagePath} from '../vite.config'

const changeConfigFn: buildUtils.ChangeConfigFn = (config, options) => {
if (!config.build) config.build = {}
if (!config.build.rollupOptions) config.build.rollupOptions = {}
if (!config.build.rollupOptions.output) config.build.rollupOptions.output = {}
config.build.rollupOptions.output = {
inlineDynamicImports: false,
manualChunks: {
monaco: ['monaco-editor', 'emmet-monaco-es']
}
}
return buildUtils.changeViteConfig(config, options)
}

Expand Down
79 changes: 40 additions & 39 deletions packages/vue-playground/src/playground/monaco/worker.ts
Original file line number Diff line number Diff line change
@@ -1,44 +1,45 @@
import {createSingletonPromise, SingletonPromiseReturn} from '@vueuse/core'

export const loadWorkers = createSingletonPromise(async () => {
return await Promise.all([
// load workers
(async () => {
const [
{default: EditorWorker},
{default: JsonWorker},
{default: HtmlWorker},
{default: TsWorker},
{default: CssWorker}
] = await Promise.all([
import('monaco-editor/esm/vs/editor/editor.worker?worker'),
import('monaco-editor/esm/vs/language/json/json.worker?worker'),
import('monaco-editor/esm/vs/language/html/html.worker?worker'),
import('monaco-editor/esm/vs/language/typescript/ts.worker?worker'),
import('monaco-editor/esm/vs/language/css/css.worker?worker')
])
return Promise.resolve()
// return await Promise.all([
// // load workers
// (async () => {
// const [
// {default: EditorWorker},
// {default: JsonWorker},
// {default: HtmlWorker},
// {default: TsWorker},
// {default: CssWorker}
// ] = await Promise.all([
// import('monaco-editor/esm/vs/editor/editor.worker?worker'),
// import('monaco-editor/esm/vs/language/json/json.worker?worker'),
// import('monaco-editor/esm/vs/language/html/html.worker?worker'),
// import('monaco-editor/esm/vs/language/typescript/ts.worker?worker'),
// import('monaco-editor/esm/vs/language/css/css.worker?worker')
// ])

self.MonacoEnvironment = {
getWorker: function (workerId, label) {
switch (label) {
case 'json':
return new JsonWorker()
case 'css':
case 'scss':
case 'less':
return new CssWorker()
case 'html':
case 'handlebars':
case 'razor':
return new HtmlWorker()
case 'typescript':
case 'javascript':
return new TsWorker()
default:
return new EditorWorker()
}
}
}
})()
])
// self.MonacoEnvironment = {
// getWorker: function (workerId, label) {
// switch (label) {
// case 'json':
// return new JsonWorker()
// case 'css':
// case 'scss':
// case 'less':
// return new CssWorker()
// case 'html':
// case 'handlebars':
// case 'razor':
// return new HtmlWorker()
// case 'typescript':
// case 'javascript':
// return new TsWorker()
// default:
// return new EditorWorker()
// }
// }
// }
// })()
// ])
}) as SingletonPromiseReturn<unknown>
5 changes: 4 additions & 1 deletion packages/vue-playground/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,11 @@ const createViteConfig = (options: CreateViteConfigOptions = {}): UserConfig =>
minify,
plugins,
alias,
formats: ['es', 'cjs'],
dedupe: ['monaco-editor'],
externalMap: {
vue: 'Vue'
vue: 'Vue',
'monaco-editor': 'monaco-editor'
}
})
}
Expand Down
7 changes: 4 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions stylelint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ module.exports = /** @type { Partial<import('stylelint').Config> } */ ({
'keyframes-name-pattern': null,
'color-function-notation': 'legacy',
'alpha-value-notation': 'number',
'no-empty-source': null,
'at-rule-no-unknown': [
true,
{
Expand Down

1 comment on commit ad261f8

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deploy preview for vue-superman ready!

✅ Preview
https://vue-superman-iligbiho4-2214962083.vercel.app

Built with commit ad261f8.
This pull request is being automatically deployed with vercel-action

Please sign in to comment.