@meethive/vite 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2118 -0
- package/dist/index.mjs +2096 -0
- package/dist/src/federation/src/dev/expose-development.d.ts +5 -0
- package/dist/src/federation/src/dev/expose-development.d.ts.map +1 -0
- package/dist/src/federation/src/dev/remote-development.d.ts +5 -0
- package/dist/src/federation/src/dev/remote-development.d.ts.map +1 -0
- package/dist/src/federation/src/dev/shared-development.d.ts +5 -0
- package/dist/src/federation/src/dev/shared-development.d.ts.map +1 -0
- package/dist/src/federation/src/index.d.ts +7 -0
- package/dist/src/federation/src/index.d.ts.map +1 -0
- package/dist/src/federation/src/prod/expose-production.d.ts +5 -0
- package/dist/src/federation/src/prod/expose-production.d.ts.map +1 -0
- package/dist/src/federation/src/prod/remote-production.d.ts +7 -0
- package/dist/src/federation/src/prod/remote-production.d.ts.map +1 -0
- package/dist/src/federation/src/prod/shared-production.d.ts +5 -0
- package/dist/src/federation/src/prod/shared-production.d.ts.map +1 -0
- package/dist/src/federation/src/public.d.ts +40 -0
- package/dist/src/federation/src/public.d.ts.map +1 -0
- package/dist/src/federation/src/runtime/dynamic-remote.d.ts +79 -0
- package/dist/src/federation/src/runtime/dynamic-remote.d.ts.map +1 -0
- package/dist/src/federation/src/utils/html.d.ts +12 -0
- package/dist/src/federation/src/utils/html.d.ts.map +1 -0
- package/dist/src/federation/src/utils/index.d.ts +29 -0
- package/dist/src/federation/src/utils/index.d.ts.map +1 -0
- package/dist/src/federation/src/utils/semver/compare.d.ts +10 -0
- package/dist/src/federation/src/utils/semver/compare.d.ts.map +1 -0
- package/dist/src/federation/src/utils/semver/constants.d.ts +11 -0
- package/dist/src/federation/src/utils/semver/constants.d.ts.map +1 -0
- package/dist/src/federation/src/utils/semver/parser.d.ts +10 -0
- package/dist/src/federation/src/utils/semver/parser.d.ts.map +1 -0
- package/dist/src/federation/src/utils/semver/satisfy.d.ts +2 -0
- package/dist/src/federation/src/utils/semver/satisfy.d.ts.map +1 -0
- package/dist/src/federation/src/utils/semver/utils.d.ts +12 -0
- package/dist/src/federation/src/utils/semver/utils.d.ts.map +1 -0
- package/dist/src/monaco-editor/index.d.ts +35 -0
- package/dist/src/monaco-editor/index.d.ts.map +1 -0
- package/dist/src/monaco-editor/languageWork.d.ts +10 -0
- package/dist/src/monaco-editor/languageWork.d.ts.map +1 -0
- package/dist/src/monaco-editor/workerMiddleware.d.ts +9 -0
- package/dist/src/monaco-editor/workerMiddleware.d.ts.map +1 -0
- package/dist/src/sharp/index.d.ts +12 -0
- package/dist/src/sharp/index.d.ts.map +1 -0
- package/index.ts +3 -0
- package/package.json +48 -0
- package/src/federation/src/dev/expose-development.ts +29 -0
- package/src/federation/src/dev/remote-development.ts +435 -0
- package/src/federation/src/dev/shared-development.ts +29 -0
- package/src/federation/src/index.ts +242 -0
- package/src/federation/src/prod/expose-production.ts +333 -0
- package/src/federation/src/prod/federation_fn_import.js +75 -0
- package/src/federation/src/prod/remote-production.ts +658 -0
- package/src/federation/src/prod/shared-production.ts +268 -0
- package/src/federation/src/public.ts +54 -0
- package/src/federation/src/runtime/dynamic-remote.ts +247 -0
- package/src/federation/src/utils/html.ts +165 -0
- package/src/federation/src/utils/index.ts +255 -0
- package/src/federation/src/utils/semver/compare.ts +131 -0
- package/src/federation/src/utils/semver/constants.ts +46 -0
- package/src/federation/src/utils/semver/parser.ts +253 -0
- package/src/federation/src/utils/semver/satisfy.ts +151 -0
- package/src/federation/src/utils/semver/utils.ts +93 -0
- package/src/federation/types/dynamic-remote.d.ts +105 -0
- package/src/federation/types/index.d.ts +344 -0
- package/src/federation/types/pluginHooks.d.ts +4 -0
- package/src/federation/types/virtual-modules.d.ts +48 -0
- package/src/federation/types/viteDevServer.d.ts +22 -0
- package/src/monaco-editor/index.ts +205 -0
- package/src/monaco-editor/languageWork.ts +36 -0
- package/src/monaco-editor/workerMiddleware.ts +78 -0
- package/src/sharp/index.ts +93 -0
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { Connect, ResolvedConfig } from 'vite';
|
|
2
|
+
import { getWorks, IMonacoEditorOpts, isCDN, resolveMonacoPath } from './index';
|
|
3
|
+
import { IWorkerDefinition } from './languageWork';
|
|
4
|
+
import { buildSync } from 'esbuild'
|
|
5
|
+
import { type RmDirOptions, existsSync, readFileSync, rmSync } from 'fs';
|
|
6
|
+
import { basename } from 'path';
|
|
7
|
+
|
|
8
|
+
export function getFilenameByEntry(entry: string) {
|
|
9
|
+
entry = basename(entry, 'js');
|
|
10
|
+
return entry + '.bundle.js';
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export const cacheDir = 'node_modules/.monaco/';
|
|
14
|
+
|
|
15
|
+
export function getWorkPath(
|
|
16
|
+
works: IWorkerDefinition[],
|
|
17
|
+
options: IMonacoEditorOpts,
|
|
18
|
+
config: ResolvedConfig
|
|
19
|
+
) {
|
|
20
|
+
const workerPaths = {};
|
|
21
|
+
|
|
22
|
+
for (const work of works) {
|
|
23
|
+
if (isCDN(options.publicPath)) {
|
|
24
|
+
workerPaths[work.label] = options.publicPath + '/' + getFilenameByEntry(work.entry);
|
|
25
|
+
} else {
|
|
26
|
+
workerPaths[work.label] =
|
|
27
|
+
config.base + options.publicPath + '/' + getFilenameByEntry(work.entry);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (workerPaths['typescript']) {
|
|
32
|
+
// javascript shares the same worker
|
|
33
|
+
workerPaths['javascript'] = workerPaths['typescript'];
|
|
34
|
+
}
|
|
35
|
+
if (workerPaths['css']) {
|
|
36
|
+
// scss and less share the same worker
|
|
37
|
+
workerPaths['less'] = workerPaths['css'];
|
|
38
|
+
workerPaths['scss'] = workerPaths['css'];
|
|
39
|
+
}
|
|
40
|
+
if (workerPaths['html']) {
|
|
41
|
+
// handlebars, razor and html share the same worker
|
|
42
|
+
workerPaths['handlebars'] = workerPaths['html'];
|
|
43
|
+
workerPaths['razor'] = workerPaths['html'];
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return workerPaths;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function workerMiddleware(
|
|
50
|
+
middlewares: Connect.Server,
|
|
51
|
+
config: ResolvedConfig,
|
|
52
|
+
options: IMonacoEditorOpts
|
|
53
|
+
): void {
|
|
54
|
+
const works = getWorks(options);
|
|
55
|
+
// clear cacheDir
|
|
56
|
+
|
|
57
|
+
if (existsSync(cacheDir)) {
|
|
58
|
+
rmSync(cacheDir, { recursive: true, force: true } as RmDirOptions);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
for (const work of works) {
|
|
62
|
+
middlewares.use(
|
|
63
|
+
config.base + options.publicPath + '/' + getFilenameByEntry(work.entry),
|
|
64
|
+
function (req, res, next) {
|
|
65
|
+
if (!existsSync(cacheDir + getFilenameByEntry(work.entry))) {
|
|
66
|
+
buildSync({
|
|
67
|
+
entryPoints: [resolveMonacoPath(work.entry)],
|
|
68
|
+
bundle: true,
|
|
69
|
+
outfile: cacheDir + getFilenameByEntry(work.entry),
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
const contentBuffer = readFileSync(cacheDir + getFilenameByEntry(work.entry));
|
|
73
|
+
res.setHeader('Content-Type', 'text/javascript');
|
|
74
|
+
res.end(contentBuffer);
|
|
75
|
+
}
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import type { Plugin } from 'vite'
|
|
2
|
+
import path from 'node:path'
|
|
3
|
+
|
|
4
|
+
// A simple Vite plugin that optimizes emitted image assets with sharp during build
|
|
5
|
+
// It runs in generateBundle to ensure we only process final assets.
|
|
6
|
+
|
|
7
|
+
export type SharpOptimizeOptions = {
|
|
8
|
+
include?: (string | RegExp)[]
|
|
9
|
+
exclude?: (string | RegExp)[]
|
|
10
|
+
jpegQuality?: number
|
|
11
|
+
pngQuality?: number // 0-100
|
|
12
|
+
webpQuality?: number
|
|
13
|
+
avifQuality?: number
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function matches(filename: string, patterns?: (string | RegExp)[]): boolean {
|
|
17
|
+
if (!patterns || patterns.length === 0) return true
|
|
18
|
+
return patterns.some((p) =>
|
|
19
|
+
typeof p === 'string' ? filename.includes(p) : (p as RegExp).test(filename)
|
|
20
|
+
)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export default function sharpOptimize(options: SharpOptimizeOptions = {}): Plugin {
|
|
24
|
+
const {
|
|
25
|
+
include,
|
|
26
|
+
exclude,
|
|
27
|
+
jpegQuality = 75,
|
|
28
|
+
pngQuality = 75,
|
|
29
|
+
webpQuality = 75,
|
|
30
|
+
avifQuality = 50,
|
|
31
|
+
} = options
|
|
32
|
+
|
|
33
|
+
// lazy require to avoid loading sharp in non-build contexts and allow it to be externalized
|
|
34
|
+
let _sharp: typeof import('sharp') | null = null
|
|
35
|
+
const getSharp = async () => {
|
|
36
|
+
if (!_sharp) {
|
|
37
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
38
|
+
const sharpModule = await import('sharp')
|
|
39
|
+
_sharp = (sharpModule.default ?? sharpModule) as typeof import('sharp')
|
|
40
|
+
}
|
|
41
|
+
return _sharp!
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const imageExts = new Set(['.png', '.jpg', '.jpeg', '.webp', '.avif'])
|
|
45
|
+
|
|
46
|
+
return {
|
|
47
|
+
name: 'jetlinks-sharp-optimize',
|
|
48
|
+
apply: 'build',
|
|
49
|
+
enforce: 'post',
|
|
50
|
+
async generateBundle(_opts, bundle) {
|
|
51
|
+
for (const [fileName, asset] of Object.entries(bundle)) {
|
|
52
|
+
if (asset.type !== 'asset') continue
|
|
53
|
+
const ext = path.extname(fileName).toLowerCase()
|
|
54
|
+
if (!imageExts.has(ext)) continue
|
|
55
|
+
if (exclude && matches(fileName, exclude)) continue
|
|
56
|
+
if (include && !matches(fileName, include)) continue
|
|
57
|
+
|
|
58
|
+
try {
|
|
59
|
+
const sourceBuffer = Buffer.isBuffer(asset.source)
|
|
60
|
+
? (asset.source as Buffer)
|
|
61
|
+
: Buffer.from(String(asset.source))
|
|
62
|
+
|
|
63
|
+
const sharp = await getSharp()
|
|
64
|
+
let instance = sharp(sourceBuffer)
|
|
65
|
+
|
|
66
|
+
switch (ext) {
|
|
67
|
+
case '.jpg':
|
|
68
|
+
case '.jpeg':
|
|
69
|
+
instance = instance.jpeg({ quality: jpegQuality, mozjpeg: true })
|
|
70
|
+
break
|
|
71
|
+
case '.png':
|
|
72
|
+
// sharp png quality maps to zlib level & palette; 0-100
|
|
73
|
+
instance = instance.png({ quality: pngQuality, compressionLevel: 9 })
|
|
74
|
+
break
|
|
75
|
+
case '.webp':
|
|
76
|
+
instance = instance.webp({ quality: webpQuality })
|
|
77
|
+
break
|
|
78
|
+
case '.avif':
|
|
79
|
+
instance = instance.avif({ quality: avifQuality })
|
|
80
|
+
break
|
|
81
|
+
default:
|
|
82
|
+
break
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const optimized = await instance.toBuffer()
|
|
86
|
+
asset.source = optimized
|
|
87
|
+
} catch (err) {
|
|
88
|
+
this.warn(`sharp optimize failed for ${fileName}: ${String(err)}`)
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
}
|
|
93
|
+
}
|