@melt-js/comps-vue3 0.0.0-stage → 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/README.md +56 -2
- package/hel_dist/css/105.95ddac72.css +1 -0
- package/hel_dist/entry.js +36 -0
- package/hel_dist/hel-meta.json +65 -0
- package/hel_dist/index.html +1 -0
- package/hel_dist/js/105.78ba830f.js +2 -0
- package/hel_dist/js/105.78ba830f.js.map +1 -0
- package/hel_dist/js/app.d7978ace.js +16 -0
- package/hel_dist/js/app.d7978ace.js.map +1 -0
- package/hel_proxy/entry.js +36 -0
- package/hel_proxy_es/entry.js +27 -0
- package/package.json +65 -4
- package/scripts/check.js +13 -0
- package/scripts/meta.js +53 -0
- package/scripts/prepublishOnly.js +27 -0
- package/scripts/preview.js +71 -0
- package/src/App.vue +26 -0
- package/src/assets/logo.png +0 -0
- package/src/components/HelloWorld.vue +57 -0
- package/src/components/index.ts +12 -0
- package/src/configs/subApp.ts +9 -0
- package/src/entrance/libProperties.ts +10 -0
- package/src/entrance/libTypes.ts +28 -0
- package/src/loadApp.ts +4 -0
- package/src/main.ts +16 -0
- package/src/shims-vue.d.ts +6 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/*
|
|
2
|
+
|--------------------------------------------------------------------------
|
|
3
|
+
| npm publish 前检查根目录下 package.json 的版本号是否和 hel_dist/hel-meta.json 一致
|
|
4
|
+
|--------------------------------------------------------------------------
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
const pkg = require('../package.json')
|
|
8
|
+
const fs = require('fs')
|
|
9
|
+
const path = require('path')
|
|
10
|
+
|
|
11
|
+
const helDistPath = path.resolve(__dirname, '../hel_dist/hel-meta.json')
|
|
12
|
+
const existHelMeata = fs.existsSync(helDistPath)
|
|
13
|
+
|
|
14
|
+
// 检查是否执行 pnpm run build 打包命令
|
|
15
|
+
if (!existHelMeata) {
|
|
16
|
+
console.log("Run the 'pnpm run build' command first.\n")
|
|
17
|
+
process.exit(1)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const { app } = JSON.parse(fs.readFileSync(helDistPath, 'utf-8'))
|
|
21
|
+
// 检查根目录下 package.json 的版本号是否和 hel_dist/hel-meta.json 一致
|
|
22
|
+
if (app?.build_version !== pkg.version) {
|
|
23
|
+
console.log(
|
|
24
|
+
'The package.json version number and the hel_dist/hel-meta.json version number must be the same.\n',
|
|
25
|
+
)
|
|
26
|
+
process.exit(1)
|
|
27
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/*
|
|
2
|
+
|--------------------------------------------------------------------------
|
|
3
|
+
| 本地预览 hel_dist 构建产物(默认 7002,带 CORS)
|
|
4
|
+
|--------------------------------------------------------------------------
|
|
5
|
+
| 预览前请先执行 `pnpm run build:local`,让产物里的资源地址指向
|
|
6
|
+
| http://localhost:7002,否则 index.html 会引用 unpkg 上的线上地址。
|
|
7
|
+
*/
|
|
8
|
+
const http = require('node:http')
|
|
9
|
+
const fs = require('node:fs')
|
|
10
|
+
const path = require('node:path')
|
|
11
|
+
|
|
12
|
+
const PORT = Number(process.env.PORT) || 7002
|
|
13
|
+
const ROOT = path.resolve(__dirname, '../hel_dist')
|
|
14
|
+
|
|
15
|
+
const MIME = {
|
|
16
|
+
'.html': 'text/html; charset=utf-8',
|
|
17
|
+
'.js': 'text/javascript; charset=utf-8',
|
|
18
|
+
'.mjs': 'text/javascript; charset=utf-8',
|
|
19
|
+
'.css': 'text/css; charset=utf-8',
|
|
20
|
+
'.json': 'application/json; charset=utf-8',
|
|
21
|
+
'.map': 'application/json; charset=utf-8',
|
|
22
|
+
'.png': 'image/png',
|
|
23
|
+
'.jpg': 'image/jpeg',
|
|
24
|
+
'.jpeg': 'image/jpeg',
|
|
25
|
+
'.gif': 'image/gif',
|
|
26
|
+
'.svg': 'image/svg+xml',
|
|
27
|
+
'.ico': 'image/x-icon',
|
|
28
|
+
'.woff': 'font/woff',
|
|
29
|
+
'.woff2': 'font/woff2',
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function send(res, status, body, headers = {}) {
|
|
33
|
+
res.writeHead(status, {
|
|
34
|
+
'Access-Control-Allow-Origin': '*',
|
|
35
|
+
'Access-Control-Allow-Methods': '*',
|
|
36
|
+
'Access-Control-Allow-Headers': '*',
|
|
37
|
+
...headers,
|
|
38
|
+
})
|
|
39
|
+
res.end(body)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
http
|
|
43
|
+
.createServer((req, res) => {
|
|
44
|
+
const urlPath = decodeURIComponent((req.url || '/').split('?')[0])
|
|
45
|
+
const relativePath = urlPath === '/' ? 'index.html' : urlPath.replace(/^\/+/, '')
|
|
46
|
+
let filePath = path.resolve(ROOT, relativePath)
|
|
47
|
+
|
|
48
|
+
// 防止路径穿越
|
|
49
|
+
if (filePath !== ROOT && !filePath.startsWith(`${ROOT}${path.sep}`)) {
|
|
50
|
+
send(res, 403, 'Forbidden')
|
|
51
|
+
return
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
fs.stat(filePath, (statErr, stat) => {
|
|
55
|
+
if (!statErr && stat.isDirectory()) {
|
|
56
|
+
filePath = path.join(filePath, 'index.html')
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
fs.readFile(filePath, (readErr, content) => {
|
|
60
|
+
if (readErr) {
|
|
61
|
+
send(res, 404, 'Not Found')
|
|
62
|
+
return
|
|
63
|
+
}
|
|
64
|
+
const contentType = MIME[path.extname(filePath).toLowerCase()] || 'application/octet-stream'
|
|
65
|
+
send(res, 200, content, { 'Content-Type': contentType })
|
|
66
|
+
})
|
|
67
|
+
})
|
|
68
|
+
})
|
|
69
|
+
.listen(PORT, () => {
|
|
70
|
+
console.log(`[comps-vue3] preview: http://localhost:${PORT}`)
|
|
71
|
+
})
|
package/src/App.vue
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<HelloWorld msg="Welcome to Your Vue.js + TypeScript + hel-micro App"/>
|
|
3
|
+
</template>
|
|
4
|
+
|
|
5
|
+
<script lang="ts">
|
|
6
|
+
import { defineComponent } from 'vue'
|
|
7
|
+
import HelloWorld from './components/HelloWorld.vue'
|
|
8
|
+
|
|
9
|
+
export default defineComponent({
|
|
10
|
+
name: 'App',
|
|
11
|
+
components: {
|
|
12
|
+
HelloWorld
|
|
13
|
+
}
|
|
14
|
+
})
|
|
15
|
+
</script>
|
|
16
|
+
|
|
17
|
+
<style>
|
|
18
|
+
#app {
|
|
19
|
+
font-family: Avenir, Helvetica, Arial, sans-serif;
|
|
20
|
+
-webkit-font-smoothing: antialiased;
|
|
21
|
+
-moz-osx-font-smoothing: grayscale;
|
|
22
|
+
text-align: center;
|
|
23
|
+
color: #2c3e50;
|
|
24
|
+
margin-top: 60px;
|
|
25
|
+
}
|
|
26
|
+
</style>
|
|
Binary file
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="hello">
|
|
3
|
+
<img alt="Vue logo" src="../assets/logo.png">
|
|
4
|
+
<h1>{{ msg }}</h1>
|
|
5
|
+
<h3>hel-micro</h3>
|
|
6
|
+
<p>
|
|
7
|
+
A module federation SDK which is unrelated to tool chain for module consumer.
|
|
8
|
+
checkout the <a href="https://tnfe.github.io/hel/" target="_blank" rel="noopener">hel-micro documentation</a>.
|
|
9
|
+
</p>
|
|
10
|
+
<button class="remote-btn" @click="count++">远程组件内部计数 {{ count }}</button>
|
|
11
|
+
</div>
|
|
12
|
+
</template>
|
|
13
|
+
|
|
14
|
+
<script lang="ts">
|
|
15
|
+
import { defineComponent, ref } from 'vue'
|
|
16
|
+
|
|
17
|
+
export default defineComponent({
|
|
18
|
+
name: 'HelloWorld',
|
|
19
|
+
props: {
|
|
20
|
+
msg: String
|
|
21
|
+
},
|
|
22
|
+
setup() {
|
|
23
|
+
// 验证远程组件复用的是宿主注入的 vue 运行时:
|
|
24
|
+
// 若是两份 vue,这里的 ref 变更不会触发宿主渲染。
|
|
25
|
+
const count = ref(0)
|
|
26
|
+
return { count }
|
|
27
|
+
}
|
|
28
|
+
})
|
|
29
|
+
</script>
|
|
30
|
+
|
|
31
|
+
<!-- Add "scoped" attribute to limit CSS to this component only -->
|
|
32
|
+
<style scoped>
|
|
33
|
+
h3 {
|
|
34
|
+
margin: 40px 0 0;
|
|
35
|
+
}
|
|
36
|
+
ul {
|
|
37
|
+
list-style-type: none;
|
|
38
|
+
padding: 0;
|
|
39
|
+
}
|
|
40
|
+
li {
|
|
41
|
+
display: inline-block;
|
|
42
|
+
margin: 0 10px;
|
|
43
|
+
}
|
|
44
|
+
a {
|
|
45
|
+
color: #42b983;
|
|
46
|
+
}
|
|
47
|
+
.remote-btn {
|
|
48
|
+
margin-top: 20px;
|
|
49
|
+
padding: 8px 16px;
|
|
50
|
+
border: 1px solid #42b983;
|
|
51
|
+
border-radius: 6px;
|
|
52
|
+
background: #fff;
|
|
53
|
+
color: #42b983;
|
|
54
|
+
font-size: 16px;
|
|
55
|
+
cursor: pointer;
|
|
56
|
+
}
|
|
57
|
+
</style>
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/*
|
|
2
|
+
|--------------------------------------------------------------------------
|
|
3
|
+
|
|
|
4
|
+
| 这些组件暴露给使用方
|
|
5
|
+
|
|
|
6
|
+
|--------------------------------------------------------------------------
|
|
7
|
+
*/
|
|
8
|
+
import HelloWorld from './HelloWorld.vue'
|
|
9
|
+
|
|
10
|
+
export default {
|
|
11
|
+
HelloWorld
|
|
12
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/*
|
|
2
|
+
|--------------------------------------------------------------------------
|
|
3
|
+
|
|
|
4
|
+
| 组件类型导出文件,同时也作为 rollup 的打包入口文件,因只提供类型,rollup 打包后是一个
|
|
5
|
+
| 仅包含 hel-lib-proxy 的空壳文件,对模块使用方的包体构建大小无影响
|
|
6
|
+
| 模块使用方 通过 npm i xxx-lib 后,只要在头文件处执行过 preFetchLib
|
|
7
|
+
| 则整个项目项使用本地模块一样载入提供方的组件,并可以点击到 node_modules 查看源码
|
|
8
|
+
|
|
|
9
|
+
|--------------------------------------------------------------------------
|
|
10
|
+
*/
|
|
11
|
+
import { exposeLib } from 'hel-lib-proxy';
|
|
12
|
+
import { LIB_NAME } from '../configs/subApp';
|
|
13
|
+
|
|
14
|
+
export type CompTypes = {
|
|
15
|
+
App: {
|
|
16
|
+
name: string,
|
|
17
|
+
},
|
|
18
|
+
HelloWorld: {
|
|
19
|
+
name: string,
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* 将提供给用户的lib暴露出去(同时也暴露了类型)
|
|
25
|
+
*/
|
|
26
|
+
export const dtlib = exposeLib<CompTypes>(LIB_NAME);
|
|
27
|
+
|
|
28
|
+
export default dtlib;
|
package/src/loadApp.ts
ADDED
package/src/main.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { isMasterApp } from 'hel-iso'
|
|
2
|
+
import { libReady } from 'hel-lib-proxy'
|
|
3
|
+
import { LIB_NAME } from './configs/subApp'
|
|
4
|
+
// import { preFetchLib } from 'hel-micro'
|
|
5
|
+
|
|
6
|
+
(async function () {
|
|
7
|
+
const libProperties = await import('./entrance/libProperties')
|
|
8
|
+
// 注意此处传递的是 default
|
|
9
|
+
libReady(LIB_NAME, libProperties.default)
|
|
10
|
+
|
|
11
|
+
// 非子应用时(即不是被别的模块触发载入的情况),自己挂载渲染节点,方便本地调试
|
|
12
|
+
// 可根据项目实际情况控制是否载入 loadApp 文件
|
|
13
|
+
if (isMasterApp()) {
|
|
14
|
+
await import('./loadApp')
|
|
15
|
+
}
|
|
16
|
+
}()).catch(console.error)
|