Skip to content

Commit ad261f8

Browse files
committed
fix(vue-playground): build error, remove monaco workers
1 parent 1707879 commit ad261f8

File tree

7 files changed

+66
-59
lines changed

7 files changed

+66
-59
lines changed

packages/superman-shared/src/build-utils/vite-config-common.util.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export const getOutputMap = (minify: boolean): Record<LibraryFormats, string> =>
2222
export interface CreateViteConfigOptions {
2323
minify?: boolean
2424
packagePath: string
25+
formats?: LibraryFormats[]
2526
externalMap?: Record<string, string>
2627
dedupe?: string[] // use the same version
2728
plugins?: PluginOption[]
@@ -33,13 +34,17 @@ export const createViteConfig = (options: CreateViteConfigOptions): UserConfig =
3334
const {
3435
minify = false,
3536
packagePath,
37+
formats = ['es', 'cjs', 'umd', 'iife'],
3638
externalMap = {},
3739
dedupe: _dedupe = [],
3840
plugins = [],
3941
alias: _alias = [],
4042
test
4143
} = options
42-
const outputMap = getOutputMap(minify)
44+
45+
const outputMap = Object.fromEntries(
46+
Object.entries(getOutputMap(minify)).filter(([format]) => formats.includes(format as LibraryFormats))
47+
) as Record<LibraryFormats, string>
4348

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

@@ -88,7 +93,10 @@ export const createViteConfig = (options: CreateViteConfigOptions): UserConfig =
8893
},
8994
rollupOptions: {
9095
output: {
91-
globals: externalMap
96+
globals: externalMap,
97+
chunkFileNames: () => {
98+
return '[format]/[name].[format].js'
99+
}
92100
},
93101
external: Object.keys(externalMap)
94102
},

packages/vue-playground/package.json

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
"main": "./dist/index.cjs",
2929
"module": "./dist/index.mjs",
3030
"types": "./dist/index.d.ts",
31-
"unpkg": "./dist/index.min.umd.js",
32-
"jsdelivr": "./dist/index.min.umd.js",
31+
"unpkg": "/dist/index.min.mjs",
32+
"jsdelivr": "/dist/index.min.mjs",
3333
"exports": {
3434
".": {
3535
"require": "./dist/index.cjs",
@@ -52,7 +52,8 @@
5252
},
5353
"homepage": "https://github.com/2214962083/vue-superman#readme",
5454
"peerDependencies": {
55-
"vue": "^3.2.0"
55+
"vue": ">=3.0.0",
56+
"monaco-editor": ">=0.30.0"
5657
},
5758
"dependencies": {
5859
"@babel/types": "^7.17.10",
@@ -63,9 +64,9 @@
6364
"@vueuse/core": "^8.4.1",
6465
"emmet-monaco-es": "^5.1.0",
6566
"js-base64": "^3.7.2",
66-
"monaco-editor": "^0.33.0",
6767
"sucrase": "^3.21.0",
68-
"theme-vitesse": "^0.4.9"
68+
"theme-vitesse": "^0.4.9",
69+
"vue-demi": "*"
6970
},
7071
"devDependencies": {
7172
"@types/node": "^17.0.24",
@@ -77,6 +78,7 @@
7778
"cross-env": "^7.0.3",
7879
"esno": "^0.14.1",
7980
"jsdom": "^19.0.0",
81+
"monaco-editor": "^0.33.0",
8082
"rimraf": "^3.0.2",
8183
"superman-shared": "workspace:*",
8284
"typescript": "4.6.3",

packages/vue-playground/scripts/build.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,6 @@ import {buildUtils} from 'superman-shared'
22
import {minifyConfig, unMinifyConfig, packagePath} from '../vite.config'
33

44
const changeConfigFn: buildUtils.ChangeConfigFn = (config, options) => {
5-
if (!config.build) config.build = {}
6-
if (!config.build.rollupOptions) config.build.rollupOptions = {}
7-
if (!config.build.rollupOptions.output) config.build.rollupOptions.output = {}
8-
config.build.rollupOptions.output = {
9-
inlineDynamicImports: false,
10-
manualChunks: {
11-
monaco: ['monaco-editor', 'emmet-monaco-es']
12-
}
13-
}
145
return buildUtils.changeViteConfig(config, options)
156
}
167

Lines changed: 40 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,45 @@
11
import {createSingletonPromise, SingletonPromiseReturn} from '@vueuse/core'
22

33
export const loadWorkers = createSingletonPromise(async () => {
4-
return await Promise.all([
5-
// load workers
6-
(async () => {
7-
const [
8-
{default: EditorWorker},
9-
{default: JsonWorker},
10-
{default: HtmlWorker},
11-
{default: TsWorker},
12-
{default: CssWorker}
13-
] = await Promise.all([
14-
import('monaco-editor/esm/vs/editor/editor.worker?worker'),
15-
import('monaco-editor/esm/vs/language/json/json.worker?worker'),
16-
import('monaco-editor/esm/vs/language/html/html.worker?worker'),
17-
import('monaco-editor/esm/vs/language/typescript/ts.worker?worker'),
18-
import('monaco-editor/esm/vs/language/css/css.worker?worker')
19-
])
4+
return Promise.resolve()
5+
// return await Promise.all([
6+
// // load workers
7+
// (async () => {
8+
// const [
9+
// {default: EditorWorker},
10+
// {default: JsonWorker},
11+
// {default: HtmlWorker},
12+
// {default: TsWorker},
13+
// {default: CssWorker}
14+
// ] = await Promise.all([
15+
// import('monaco-editor/esm/vs/editor/editor.worker?worker'),
16+
// import('monaco-editor/esm/vs/language/json/json.worker?worker'),
17+
// import('monaco-editor/esm/vs/language/html/html.worker?worker'),
18+
// import('monaco-editor/esm/vs/language/typescript/ts.worker?worker'),
19+
// import('monaco-editor/esm/vs/language/css/css.worker?worker')
20+
// ])
2021

21-
self.MonacoEnvironment = {
22-
getWorker: function (workerId, label) {
23-
switch (label) {
24-
case 'json':
25-
return new JsonWorker()
26-
case 'css':
27-
case 'scss':
28-
case 'less':
29-
return new CssWorker()
30-
case 'html':
31-
case 'handlebars':
32-
case 'razor':
33-
return new HtmlWorker()
34-
case 'typescript':
35-
case 'javascript':
36-
return new TsWorker()
37-
default:
38-
return new EditorWorker()
39-
}
40-
}
41-
}
42-
})()
43-
])
22+
// self.MonacoEnvironment = {
23+
// getWorker: function (workerId, label) {
24+
// switch (label) {
25+
// case 'json':
26+
// return new JsonWorker()
27+
// case 'css':
28+
// case 'scss':
29+
// case 'less':
30+
// return new CssWorker()
31+
// case 'html':
32+
// case 'handlebars':
33+
// case 'razor':
34+
// return new HtmlWorker()
35+
// case 'typescript':
36+
// case 'javascript':
37+
// return new TsWorker()
38+
// default:
39+
// return new EditorWorker()
40+
// }
41+
// }
42+
// }
43+
// })()
44+
// ])
4445
}) as SingletonPromiseReturn<unknown>

packages/vue-playground/vite.config.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,11 @@ const createViteConfig = (options: CreateViteConfigOptions = {}): UserConfig =>
3030
minify,
3131
plugins,
3232
alias,
33+
formats: ['es', 'cjs'],
34+
dedupe: ['monaco-editor'],
3335
externalMap: {
34-
vue: 'Vue'
36+
vue: 'Vue',
37+
'monaco-editor': 'monaco-editor'
3538
}
3639
})
3740
}

pnpm-lock.yaml

Lines changed: 4 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

stylelint.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ module.exports = /** @type { Partial<import('stylelint').Config> } */ ({
4949
'keyframes-name-pattern': null,
5050
'color-function-notation': 'legacy',
5151
'alpha-value-notation': 'number',
52+
'no-empty-source': null,
5253
'at-rule-no-unknown': [
5354
true,
5455
{

0 commit comments

Comments
 (0)