Skip to content

Commit 1cf8e5c

Browse files
committed
Merge branch 'development'
2 parents 5f1c184 + 4765e9c commit 1cf8e5c

39 files changed

+1673
-24
lines changed

.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/build
22
/example
33
/node_modules
4+
/packages
45
/src
56
/docs
67
/old
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
target/
2+
!.mvn/wrapper/maven-wrapper.jar
3+
4+
__test__
5+
6+
# OS Files
7+
.DS_Store
8+
Thumbs.db
9+
10+
# Dependencies
11+
node_modules/
12+
# demo or example files
13+
/example
14+
# portal pacakge files
15+
/pacakge
16+
17+
# Local Env Files
18+
.env.local
19+
.env.*.local
20+
21+
# Log Files
22+
*.log
23+
npm-debug.log*
24+
yarn-debug.log*
25+
yarn-error.log*
26+
27+
# Unconfigured Editors
28+
.vscode
29+
.idea
30+
*.suo
31+
*.ntvs*
32+
*.njsproj
33+
*.sln
34+
*.sw*
35+
### IntelliJ IDEA ###
36+
.idea
37+
*.iws
38+
*.iml
39+
*.ipr
40+
# Editor directories and files
41+
*.suo
42+
*.ntvs*
43+
*.njsproj
44+
*.sln
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/screenshots
2+
/__test__
3+
/node_modules
4+
.gitignore
5+
.npmrc
6+
*.log
7+
8+
# OS Files
9+
.DS_Store
10+
Thumbs.db

packages/vue-cli-plugin-mfe/README.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
---
2+
title: 介绍
3+
lang: zh-CN
4+
meta:
5+
- name: description
6+
content: vue-cli-plugin-mfe
7+
- name: keywords
8+
content: vue, vue-mfe, VUE-MFE, vue-cli-plugin-mfe
9+
---
10+
11+
# vue-cli-plugin-mfe
12+
13+
为 vue-mfe 的 domain-app 量身打造的 Vue-CLI3 插件.
14+
15+
16+
## FEATURES
17+
18+
### 可选的主运行时
19+
支持可选的 `master-runtime` 配置,并根据是否选择 master 的配置生成相应的 `alias``entry`
20+
21+
### 自动配置 linters
22+
集成 `eslint-standard`, `eslint-prettier`, `prettier/standard`, `prettier/vue`, `style-lint`, `vue-config` 等自动 lint 工具,无需再耗费心里手动维护配置依赖和规则
23+
24+
### friendly alias
25+
根据 `aliases.config.js` 自动生成 VSCode friendly `jsconfig.json` 方便别名跳转 peek,无需手动去寻找/记住别名定义
26+
27+
### vue-cli-service package
28+
`domain-app` 专属的打包命令,与原先的 `build` 命令做的事情非常类似。
29+
30+
+ 更改 package 时候的 webpack entry 和 plugins,以 `['./src/portal.entry.js', './src/routes', './src/router/routes.js', './src/routes.js', './src/main.js']` 为基础自动探测在执行 `package``webpack` 依赖的入口 `entry`
31+
+ 集成 `webpack-require-from` 指定 domain runtime 的 CDN `download` 主机地址
32+
+ 集成 `webpack-manifest-plugin` 收集版本和 built 之后的文件信息
33+
+ 集成 `node-archiver` 打成 `tar` 包并上传到指定的 `host`
34+
+ 自动压缩打包📦文件成 `.tar.gz` 并上传到指定 package-server.
35+
36+
37+
## API
38+
39+
查看用法:
40+
```bash
41+
vue-cli-service help package
42+
```
43+
44+
```bash
45+
用法:'vue-cli-service package [options]'
46+
选项:{
47+
description: 'Package to .tgr.gz and upload to server',
48+
usage: 'vue-cli-service package [options]',
49+
options: {
50+
'--host': `specify package-server API url to upload bundled files`,
51+
'--download': `specify package-server API url to download static files`,
52+
'--name': `specify the name of current bundle package? default: ${PACKAGE_NAME}`,
53+
'--output': `specify the output path of bundle files? default: package => ${cwd}/package`,
54+
'--upload': `upload bundle file to server or not? default: true`,
55+
'--json': `output bundle manifest json or not? default: true => manifest.json`,
56+
'--disable-source-map': `disable source map. default: false`,
57+
},
58+
}
59+
```
60+
61+
62+
## RUN
63+
64+
```bash
65+
vue-cli-service package
66+
```
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
/**
2+
* inspired from:
3+
* 1. https://github.com/vuejs/vue-cli/blob/dev/packages/%40vue/cli-service/lib/commands/build/index.js
4+
* */
5+
'use strict'
6+
const webpack = require('webpack')
7+
const path = require('path')
8+
const rimraf = require('rimraf')
9+
const formatStats = require('@vue/cli-service/lib/commands/build/formatStats')
10+
11+
const defaults = {
12+
clean: true,
13+
target: 'lib',
14+
formats: 'commonjs,umd,umd-min',
15+
'unsafe-inline': true,
16+
}
17+
18+
const buildModes = {
19+
lib: 'library',
20+
wc: 'web component',
21+
'wc-async': 'web component (async)',
22+
}
23+
24+
module.exports = async function build(args, api, options) {
25+
const {
26+
chalk,
27+
log,
28+
done,
29+
info,
30+
logWithSpinner,
31+
stopSpinner,
32+
} = require('@vue/cli-shared-utils')
33+
34+
for (const key in defaults) {
35+
if (args[key] == null) {
36+
args[key] = defaults[key]
37+
}
38+
}
39+
40+
log()
41+
const mode = api.service.mode
42+
const targetDir = api.resolve(args.dest || args.output || options.outputDir)
43+
44+
if (args.target === 'app') {
45+
const bundleTag = args.modern
46+
? args.modernBuild
47+
? `modern bundle `
48+
: `legacy bundle `
49+
: ``
50+
logWithSpinner(`Building ${bundleTag}for ${mode}...`)
51+
} else {
52+
const buildMode = buildModes[args.target]
53+
54+
if (buildMode) {
55+
const additionalParams =
56+
buildMode === 'library' ? ` (${args.formats})` : ``
57+
logWithSpinner(
58+
`Building for ${mode} as ${buildMode}${additionalParams}...`
59+
)
60+
} else {
61+
throw new Error(`Unknown build target: ${args.target}`)
62+
}
63+
}
64+
65+
return new Promise((resolve, reject) => {
66+
rimraf(targetDir, (error) => {
67+
if (error) return reject('Rimraf failed: ' + dest + ' => ' + error)
68+
else {
69+
webpack(api.resolveWebpackConfig(), (err, stats) => {
70+
stopSpinner(false)
71+
72+
if (err) {
73+
return reject(err)
74+
}
75+
76+
if (stats.hasErrors()) {
77+
return reject(`Build failed with errors.`)
78+
}
79+
80+
if (!args.silent) {
81+
const targetDirShort = path.relative(api.service.context, targetDir)
82+
log(formatStats(stats, targetDirShort, api))
83+
84+
if (args.target === 'app' && !isLegacyBuild) {
85+
if (!args.watch) {
86+
done(
87+
`Build complete. The ${chalk.cyan(
88+
targetDirShort
89+
)} directory is ready to be deployed.`
90+
)
91+
info(
92+
`Check out deployment instructions at ${chalk.cyan(
93+
`https://cli.vuejs.org/guide/deployment.html`
94+
)}\n`
95+
)
96+
} else {
97+
done(`Build complete. Watching for changes...`)
98+
}
99+
}
100+
}
101+
102+
// test-only signal
103+
if (process.env.VUE_CLI_TEST) {
104+
console.log('Build complete.')
105+
}
106+
107+
resolve()
108+
})
109+
}
110+
})
111+
})
112+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
'use strict'
2+
3+
const fs = require('fs')
4+
const FormData = require('form-data')
5+
const {
6+
chalk,
7+
log,
8+
done,
9+
info,
10+
logWithSpinner,
11+
stopSpinner
12+
} = require('@vue/cli-shared-utils')
13+
14+
module.exports = async function(args, file) {
15+
const name = args.name
16+
const url = args.uploadUrl
17+
const download = args.downloadUrl || args.uploadUrl
18+
const fileSize = fs.statSync(file).size
19+
20+
log()
21+
log(
22+
JSON.stringify({
23+
name,
24+
uploadUrl: url,
25+
downloadUrl: download,
26+
file,
27+
fileSize
28+
})
29+
)
30+
log()
31+
32+
return new Promise((resolve, reject) => {
33+
logWithSpinner(`start uploading ${name} to package-server ${url}...`)
34+
35+
const formData = new FormData({})
36+
37+
formData.append('file', fs.createReadStream(file), {
38+
headers: { 'transfer-encoding': 'chunked' },
39+
knownLength: fileSize
40+
})
41+
42+
formData.submit(url, (err, res) => {
43+
stopSpinner(false)
44+
45+
if (err) {
46+
log(chalk.red(`Publish module ${chalk.cyan(name)} failed`))
47+
log(chalk.red(err))
48+
reject(err)
49+
50+
process.exit(1)
51+
} else if (res.statusCode !== 200) {
52+
log(chalk.red(`Publish module ${chalk.cyan(name)} failed`))
53+
log(
54+
chalk.red(
55+
`Remote server ${url} Status error. Code: ${chalk.red(
56+
res.statusCode
57+
)}, Body: ${chalk.red(res.statusMessage)}`
58+
)
59+
)
60+
61+
process.exit(1)
62+
} else {
63+
done(`Upload module ${chalk.yellow(name)} complete.`)
64+
info(`Checkout it out on package-server ${chalk.cyan(`${download}`)}`)
65+
66+
resolve(res.resume())
67+
}
68+
})
69+
})
70+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/**
2+
* # Generator
3+
* https://cli.vuejs.org/dev-guide/plugin-dev.html#generator
4+
* [Generator API Source Code](https://github.com/vuejs/vue-cli/blob/dev/packages/%40vue/cli/lib/GeneratorAPI.js)
5+
*
6+
* + #entry It will be invoked in two possible scenarios:
7+
* 1. During a project's initial creation, if the CLI plugin is installed as part of the project creation preset.
8+
* 2. When the plugin is installed after project's creation and invoked individually via vue add or `vue invoke`.
9+
*
10+
* + #usage
11+
* 1. see [creating new templates、files or edit existing ones](https://cli.vuejs.org/dev-guide/plugin-dev.html#creating-new-templates)
12+
* 2. see [filename edge cases](https://cli.vuejs.org/dev-guide/plugin-dev.html#filename-edge-cases)
13+
* 3. see [extending package](https://cli.vuejs.org/dev-guide/plugin-dev.html#extending-package)
14+
* 4. see [changing main file](https://cli.vuejs.org/dev-guide/plugin-dev.html#changing-main-file)
15+
*
16+
* + #params A generator should export a function which receives three arguments:
17+
* 1. A [Generator API](https://cli.vuejs.org/dev-guide/generator-api.html#generator-api) instance;
18+
* 2. The generator options for this plugin.
19+
* 2.1 These options are resolved during the prompt phase of project creation,
20+
* 2.2 or loaded from a saved preset in [~/.vuerc](~/.vuerc).
21+
*/
22+
23+
module.exports = (api /* see #params.1 */, options /* see #params.2 */) => {
24+
const {
25+
useMasterRuntime,
26+
masterRuntimeName,
27+
masterRuntimeVersion,
28+
domainRoutePrefix,
29+
} = options
30+
31+
api.extendPackage({
32+
scripts: {
33+
package: 'vue-cli-service package',
34+
start: 'npm run serve',
35+
dev: 'npm run serve',
36+
},
37+
devDependencies: {
38+
'@vue/eslint-config-prettier': '^4.0.1',
39+
'@vue/eslint-config-standard': '^4.0.0',
40+
},
41+
})
42+
43+
/* see #usage.1 [creating new templates] */
44+
/* see #usage.2 [filename edge cases] */
45+
if (useMasterRuntime) {
46+
api.render('./template', {
47+
masterRuntimeName,
48+
domainRoutePrefix,
49+
})
50+
51+
// https://cli.vuejs.org/dev-guide/plugin-dev.html#service-plugin
52+
// An object containing project local options specified in vue.config.js, or in the "vue" field in package.json.
53+
api.extendPackage({
54+
dependencies: {
55+
[masterRuntimeName]: masterRuntimeVersion,
56+
},
57+
'portal-config': {
58+
useMasterRuntime,
59+
masterRuntimeName,
60+
masterRuntimeVersion,
61+
domainRoutePrefix,
62+
},
63+
})
64+
65+
api.onCreateComplete(() => {
66+
const fs = require('fs')
67+
const entryJSFile = api.resolve('src/main.js')
68+
if (fs.existsSync(entryJSFile)) {
69+
fs.unlinkSync(entryJSFile)
70+
}
71+
72+
const appVueFile = api.resolve('src/App.vue')
73+
if (fs.existsSync(appVueFile)) {
74+
fs.unlinkSync(appVueFile)
75+
}
76+
})
77+
}
78+
}

0 commit comments

Comments
 (0)