Skip to content

Commit

Permalink
refactor(cli): plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
fxy060608 committed Mar 27, 2020
1 parent 044b439 commit cb1435d
Show file tree
Hide file tree
Showing 52 changed files with 1,003 additions and 803 deletions.
49 changes: 49 additions & 0 deletions lib/h5/uni.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
const fs = require('fs')
const path = require('path')

function getTemplatePath(template) {
if (template) {
return path.resolve(process.env.UNI_INPUT_DIR, template)
}
return path.resolve(process.env.UNI_CLI_CONTEXT, 'public/index.html')
}

function transform(content) {
if (process.env.NODE_ENV === 'production') {
return content + // shadow
`body::after{position:fixed;content:'';left:-1000px;top:-1000px;-webkit-animation:shadow-preload .1s;-webkit-animation-delay:3s;animation:shadow-preload .1s;animation-delay:3s}@-webkit-keyframes shadow-preload{0%{background-image:url(https://cdn.dcloud.net.cn/img/shadow-grey.png)}100%{background-image:url(https://cdn.dcloud.net.cn/img/shadow-grey.png)}}@keyframes shadow-preload{0%{background-image:url(https://cdn.dcloud.net.cn/img/shadow-grey.png)}100%{background-image:url(https://cdn.dcloud.net.cn/img/shadow-grey.png)}}`
}
return content
}

function getIndexCssPath(assetsDir, template) {
const VUE_APP_INDEX_CSS_HASH = process.env.VUE_APP_INDEX_CSS_HASH
if (VUE_APP_INDEX_CSS_HASH) {
try {
const templateContent = fs.readFileSync(getTemplatePath(template))
if (/\bVUE_APP_INDEX_CSS_HASH\b/.test(templateContent)) {
return path.join(assetsDir, `[name].${VUE_APP_INDEX_CSS_HASH}.[ext]`)
}
} catch (e) {}
}
return assetsDir
}

module.exports = {
options: {
cssVars: {
'--status-bar-height': '0px'
},
filterTag: 'wxs',
vue: '@dcloudio/vue-cli-plugin-uni/packages/h5-vue'
},
copyWebpackOptions(platformOptions, vueOptions) {
return [{
from: require.resolve('@dcloudio/uni-h5/dist/index.css'),
to: getIndexCssPath(vueOptions.assetsDir, platformOptions.template),
transform
},
'hybrid/html'
]
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"scripts": {
"build:service:legacy": "npm run lint && rollup -c build/rollup.config.service.js",
"lint": "eslint --fix --config package.json --ext .js --ext .vue --ignore-path .eslintignore build src",
"lint:cli": "eslint --fix --config package.json --ext .js --ext .vue --ignore-path .eslintignore packages/uni-cli-shared packages/uni-template-compiler \"packages/vue-cli-*/**/*.js\" \"packages/webpack-uni-*/**/*.js\"",
"lint:cli": "eslint --fix --config package.json --ext .js --ext .vue --ignore-path .eslintignore packages/uni-cli-shared packages/uni-template-compiler \"packages/uni-*/lib/*.js\" \"packages/vue-cli-*/**/*.js\" \"packages/webpack-uni-*/**/*.js\"",
"dev:h5": "npm run lint && cross-env NODE_ENV=production UNI_WATCH=true UNI_PLATFORM=h5 node build/build.js",
"build:h5": "npm run lint && cross-env NODE_ENV=production UNI_WATCH=false UNI_PLATFORM=h5 node build/build.js",
"build:h5:ui": "cross-env NODE_ENV=production UNI_WATCH=false UNI_PLATFORM=h5 UNI_UI=true node build/build.js",
Expand Down
44 changes: 44 additions & 0 deletions packages/uni-app-plus/lib/uni.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
const fs = require('fs')
const path = require('path')

const COMPONENTS_DIR_NAME = 'wxcomponents'

function getComponentsCopyOption () {
if (process.env.UNI_OUTPUT_TMP_DIR) { // TODO v3不需要,即将废弃
const componentsDir = path.resolve(process.env.UNI_INPUT_DIR, COMPONENTS_DIR_NAME)
if (fs.existsSync(componentsDir)) {
return {
from: componentsDir,
to: COMPONENTS_DIR_NAME,
ignore: ['**/*.vue', '**/*.css']
}
}
}
}

module.exports = {
options: {
extnames: { // TODO v3不需要此配置
style: '.wxss',
template: '.wxml',
filter: '.wxs'
},
filterTag: 'wxs'
},
copyWebpackOptions (platformOptions, vueOptions) {
const copyOptions = []
const componentsCopyOption = getComponentsCopyOption()
if (componentsCopyOption) {
copyOptions.push(componentsCopyOption)
}
copyOptions.push('hybrid/html')
if (process.env.UNI_USING_V3) { // TODO 将仅保留v3逻辑
copyOptions.push(path.resolve(__dirname, '../dist/view.css'))
copyOptions.push(path.resolve(__dirname, '../dist/view.umd.min.js'))
// TODO 后续common与v3目录应该合并
copyOptions.push(path.resolve(__dirname, '../template/common'))
copyOptions.push(path.resolve(__dirname, '../template/v3'))
}
return copyOptions
}
}
36 changes: 20 additions & 16 deletions packages/uni-app-plus/package.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
{
"name": "@dcloudio/uni-app-plus",
"version": "2.0.0-alpha-26420200309002",
"description": "uni-app app-plus",
"main": "dist/index.js",
"repository": {
"type": "git",
"url": "git+https://github.com/dcloudio/uni-app.git",
"directory": "packages/uni-app-plus"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "fxy060608",
"license": "Apache-2.0",
"gitHead": "84e9cb1ca1898054d161f1514efadd1ab24fd804"
{
"name": "@dcloudio/uni-app-plus",
"version": "2.0.0-alpha-26420200309002",
"description": "uni-app app-plus",
"main": "dist/index.js",
"repository": {
"type": "git",
"url": "git+https://github.com/dcloudio/uni-app.git",
"directory": "packages/uni-app-plus"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "fxy060608",
"license": "Apache-2.0",
"uni-app": {
"name": "app-plus",
"title": "APP-PLUS"
},
"gitHead": "84e9cb1ca1898054d161f1514efadd1ab24fd804"
}

Large diffs are not rendered by default.

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions packages/uni-app-plus/template/common/__uniapppicker.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions packages/uni-app-plus/template/common/__uniappscan.js

Large diffs are not rendered by default.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions packages/uni-app-plus/template/v3/__uniappes6.js

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions packages/uni-app-plus/template/v3/__uniappquill.js

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 28 additions & 0 deletions packages/uni-app-plus/template/v3/__uniappview.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<!DOCTYPE html>
<html lang="zh-CN">

<head>
<meta charset="UTF-8" />
<script>
var __UniViewStartTime__ = Date.now();
document.addEventListener('DOMContentLoaded', function() {
document.documentElement.style.fontSize = document.documentElement.clientWidth / 20 + 'px'
})
var coverSupport = 'CSS' in window && typeof CSS.supports === 'function' && (CSS.supports('top: env(a)') ||
CSS.supports('top: constant(a)'))
document.write(
'<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0' +
(coverSupport ? ', viewport-fit=cover' : '') + '" />')
</script>
<title>View</title>
<link rel="stylesheet" href="view.css" />
</head>

<body>
<div id="app"></div>
<script src="__uniappes6.js"></script>
<script src="view.umd.min.js"></script>
<script src="app-view.js"></script>
</body>

</html>
10 changes: 2 additions & 8 deletions packages/uni-cli-shared/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,13 @@ const {
getPlatformProject,
isSupportSubPackages,
getPlatforms,
getPlatformGlobal,
getPlatformScss,
getPlatformSass,
runByHBuilderX,
isInHBuilderX,
isInHBuilderXAlpha,
getPlatformExts,
getPlatformTarget,
getPlatformVue,
getShadowCss,
getPlatformCssVars,
getPlatformCssnano,
Expand All @@ -58,8 +56,7 @@ const {
htmlPreprocessOptions,
nvueJsPreprocessOptions,
nvueCssPreprocessOptions,
nvueHtmlPreprocessOptions,
devtoolModuleFilenameTemplate
nvueHtmlPreprocessOptions
} = require('./platform')

module.exports = {
Expand Down Expand Up @@ -93,8 +90,6 @@ module.exports = {
getPlatformExts,
getPlatformTarget,
getPlatformProject,
getPlatformVue,
getPlatformGlobal,
getShadowCss,
getPlatformCssVars,
getPlatformCssnano,
Expand All @@ -109,6 +104,5 @@ module.exports = {
htmlPreprocessOptions,
nvueJsPreprocessOptions,
nvueCssPreprocessOptions,
nvueHtmlPreprocessOptions,
devtoolModuleFilenameTemplate
nvueHtmlPreprocessOptions
}
9 changes: 7 additions & 2 deletions packages/uni-cli-shared/lib/manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ function getH5Options (manifestJson) {
if (!h5.publicPath.endsWith('/')) {
h5.publicPath = h5.publicPath + '/'
}
} else { // 其他模式,启用 base
} else { // 其他模式,启用 base
if (base.startsWith('./')) {
// 在开发模式, publicPath 如果为 './' webpack-dev-server 匹配文件时会失败
h5.publicPath = base.substr(1)
Expand All @@ -90,6 +90,11 @@ function getH5Options (manifestJson) {

h5.devServer = h5.devServer || {}

// 插件修改 h5Options
global.uniPlugin.configureH5.forEach(configureH5 => {
configureH5(h5)
})

return h5
}

Expand All @@ -98,4 +103,4 @@ module.exports = {
parseManifestJson,
getNetworkTimeout,
getH5Options
}
}
Loading

0 comments on commit cb1435d

Please sign in to comment.