From 6a75f845d3d836a38c9b7151f8dd7e9b5dc062f4 Mon Sep 17 00:00:00 2001 From: fxy060608 Date: Thu, 29 Jul 2021 10:51:13 +0800 Subject: [PATCH] wip(app): nvue --- package.json | 1 + .../uni-app-plus/dist/uni-app-service.es.js | 36 ++--- .../uni-app-plus/dist/uni-app-view.umd.js | 2 +- packages/uni-cli-nvue/dist/index.js | 3 + .../dist/webpack/config/module/rules/index.js | 20 +-- .../dist/webpack/config/plugins/vueLoader.js | 2 +- .../uni-cli-nvue/lib/vue-loader/package.json | 153 +++++++++--------- packages/uni-cli-nvue/package.json | 12 +- packages/uni-cli-nvue/src/index.ts | 3 + .../src/webpack/config/module/rules/index.ts | 20 +-- .../src/webpack/config/optimization.ts | 1 + .../src/webpack/config/plugins/vueLoader.ts | 2 +- packages/vite-plugin-uni/src/cli/action.ts | 4 +- packages/vite-plugin-uni/tsconfig.json | 3 +- 14 files changed, 124 insertions(+), 138 deletions(-) diff --git a/package.json b/package.json index da989122e..ed854f2fa 100644 --- a/package.json +++ b/package.json @@ -80,6 +80,7 @@ "mini-types": "^0.1.4", "miniprogram-api-typings": "^3.4.0", "module-alias": "^2.2.2", + "postcss": "^8.3.6", "postcss-load-config": "^3.1.0", "prettier": "^2.2.1", "rollup": "^2.35.1", diff --git a/packages/uni-app-plus/dist/uni-app-service.es.js b/packages/uni-app-plus/dist/uni-app-service.es.js index 703c62fa6..9e60cfab8 100644 --- a/packages/uni-app-plus/dist/uni-app-service.es.js +++ b/packages/uni-app-plus/dist/uni-app-service.es.js @@ -6072,7 +6072,15 @@ var serviceContext = (function (vue) { return new Page(page); } - function getStatusBarStyle$1() { + function getStatusbarHeight() { + // 横屏时 iOS 获取的状态栏高度错误,进行纠正 + return plus.navigator.isImmersedStatusbar() + ? Math.round(plus.os.name === 'iOS' + ? plus.navigator.getSafeAreaInsets().top + : plus.navigator.getStatusbarHeight()) + : 0; + } + function getStatusBarStyle() { let style = plus.navigator.getStatusBarStyle(); if (style === 'UIStatusBarStyleBlackTranslucent' || style === 'UIStatusBarStyleBlackOpaque' || @@ -6083,11 +6091,12 @@ var serviceContext = (function (vue) { style = 'dark'; } return style; - } + } + const scanCode = defineAsyncApi(API_SCAN_CODE, (options, { resolve, reject }) => { initI18nScanCodeMsgsOnce(); const { t } = useI18n(); - const statusBarStyle = getStatusBarStyle$1(); + const statusBarStyle = getStatusBarStyle(); const isDark = statusBarStyle !== 'light'; let result; let success = false; @@ -7891,18 +7900,6 @@ var serviceContext = (function (vue) { }); }, GetLocationProtocol, GetLocationOptions); - function getStatusBarStyle() { - let style = plus.navigator.getStatusBarStyle(); - if (style === 'UIStatusBarStyleBlackTranslucent' || - style === 'UIStatusBarStyleBlackOpaque' || - style === 'null') { - style = 'light'; - } - else if (style === 'UIStatusBarStyleDefault') { - style = 'dark'; - } - return style; - } const chooseLocation = defineAsyncApi(API_CHOOSE_LOCATION, (options, { resolve, reject }) => { const statusBarStyle = getStatusBarStyle(); const isDark = statusBarStyle !== 'light'; @@ -10528,15 +10525,6 @@ var serviceContext = (function (vue) { return routeOptions; } - function getStatusbarHeight() { - // 横屏时 iOS 获取的状态栏高度错误,进行纠正 - return plus.navigator.isImmersedStatusbar() - ? Math.round(plus.os.name === 'iOS' - ? plus.navigator.getSafeAreaInsets().top - : plus.navigator.getStatusbarHeight()) - : 0; - } - function registerPage({ url, path, query, openType, webview, vm, }) { // fast 模式,nvue 首页时,会在nvue中主动调用registerPage并传入首页webview,此时初始化一下首页(因为此时可能还未调用registerApp) if (webview) { diff --git a/packages/uni-app-plus/dist/uni-app-view.umd.js b/packages/uni-app-plus/dist/uni-app-view.umd.js index af234d3c7..88c331fa8 100644 --- a/packages/uni-app-plus/dist/uni-app-view.umd.js +++ b/packages/uni-app-plus/dist/uni-app-view.umd.js @@ -15773,7 +15773,7 @@ if (parentTitleNView) { let defaultTop = NAVBAR_HEIGHT + parseFloat(styles.top || "0"); if (plus.navigator.isImmersedStatusbar()) { - defaultTop += plus.navigator.getStatusbarHeight(); + defaultTop += getStatusbarHeight(); } styles.top = String(defaultTop); styles.bottom = styles.bottom || "0"; diff --git a/packages/uni-cli-nvue/dist/index.js b/packages/uni-cli-nvue/dist/index.js index 6034624f0..6addd80ed 100644 --- a/packages/uni-cli-nvue/dist/index.js +++ b/packages/uni-cli-nvue/dist/index.js @@ -10,4 +10,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); }; Object.defineProperty(exports, "__esModule", { value: true }); +/** + * 注意:该包的依赖包含了 lib 中的 vue-loader,weex-styler,weex-template-compiler + */ __exportStar(require("./webpack"), exports); diff --git a/packages/uni-cli-nvue/dist/webpack/config/module/rules/index.js b/packages/uni-cli-nvue/dist/webpack/config/module/rules/index.js index dfd6d9097..8dce87f64 100644 --- a/packages/uni-cli-nvue/dist/webpack/config/module/rules/index.js +++ b/packages/uni-cli-nvue/dist/webpack/config/module/rules/index.js @@ -1,20 +1,6 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.rules = void 0; -exports.rules = [ - { - test: [/\.nvue(\?[^?]+)?$/, /\.vue(\?[^?]+)?$/], - loader: 'vue-loader', - }, - { - test: /\.js$/, - use: [ - { - loader: 'babel-loader', - options: { - babelrc: false, - }, - }, - ], - }, -]; +const babelLoader_1 = require("./babelLoader"); +const vueLoader_1 = require("./vueLoader"); +exports.rules = [vueLoader_1.vueLoader, babelLoader_1.babelLoader]; diff --git a/packages/uni-cli-nvue/dist/webpack/config/plugins/vueLoader.js b/packages/uni-cli-nvue/dist/webpack/config/plugins/vueLoader.js index 4e60eb834..22824e891 100644 --- a/packages/uni-cli-nvue/dist/webpack/config/plugins/vueLoader.js +++ b/packages/uni-cli-nvue/dist/webpack/config/plugins/vueLoader.js @@ -1,5 +1,5 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.vueLoaderPlugin = void 0; -const { VueLoaderPlugin } = require('../../../../lib/vue-loader/dist'); +const { VueLoaderPlugin } = require('../../../../lib/vue-loader'); exports.vueLoaderPlugin = new VueLoaderPlugin(); diff --git a/packages/uni-cli-nvue/lib/vue-loader/package.json b/packages/uni-cli-nvue/lib/vue-loader/package.json index 21abbed10..586292590 100644 --- a/packages/uni-cli-nvue/lib/vue-loader/package.json +++ b/packages/uni-cli-nvue/lib/vue-loader/package.json @@ -1,95 +1,104 @@ { "name": "vue-loader", - "version": "16.3.3", - "license": "MIT", - "author": "Evan You", - "main": "dist/index.js", - "types": "dist/index.d.ts", - "files": [ - "dist" - ], + "version": "15.9.7", + "description": "Vue single-file component loader for Webpack", + "main": "lib/index.js", + "typings": "lib/index.d.ts", "scripts": { - "dev": "tsc --watch", - "build": "tsc", - "pretest": "tsc", - "test": "jest --coverage", - "test:webpack5": "WEBPACK5=true jest -c --coverage", - "dev-example": "webpack-dev-server --config example/webpack.config.js --inline --hot", - "build-example": "rm -rf example/dist && webpack --config example/webpack.config.js --env.prod", - "build-example-ssr": "rm -rf example/dist-ssr && webpack --config example/webpack.config.js --env.prod --env.ssr && node example/ssr.js", - "lint": "prettier --write --parser typescript \"{src,test}/**/*.{j,t}s\"", - "prepublishOnly": "tsc && conventional-changelog -p angular -i CHANGELOG.md -s -r 2" + "test": "yarn lint && jest --env node", + "lint": "eslint lib test --fix", + "build": "webpack --config example/webpack.config.js --hide-modules", + "dev": "webpack-dev-server --config example/webpack.config.js --inline --hot", + "docs": "vuepress dev docs", + "docs:build": "vuepress build docs", + "prepublishOnly": "conventional-changelog -p angular -r 2 -i CHANGELOG.md -s" + }, + "author": "Evan You", + "license": "MIT", + "bugs": { + "url": "https://github.com/vuejs/vue-loader/issues" + }, + "homepage": "https://github.com/vuejs/vue-loader", + "repository": { + "type": "git", + "url": "https://github.com/vuejs/vue-loader.git" }, "gitHooks": { "pre-commit": "lint-staged" }, "lint-staged": { - "*.js": [ - "prettier --write" + "lib/**/*.js": [ + "eslint --fix", + "git add" ], - "*.ts": [ - "prettier --parser=typescript --write" + "test/**/*.js": [ + "eslint --fix", + "git add" ] }, - "dependencies": { - "chalk": "^4.1.0", - "hash-sum": "^2.0.0", - "loader-utils": "^2.0.0" - }, "peerDependencies": { - "@vue/compiler-sfc": "^3.0.8", - "webpack": "^4.1.0 || ^5.0.0-0" + "css-loader": "*", + "webpack": "^3.0.0 || ^4.1.0 || ^5.0.0-0" }, "peerDependenciesMeta": { - "@vue/compiler-sfc": { + "cache-loader": { + "optional": true + }, + "vue-template-compiler": { "optional": true } }, + "dependencies": { + "@vue/component-compiler-utils": "^3.1.0", + "hash-sum": "^1.0.2", + "loader-utils": "^1.1.0", + "vue-hot-reload-api": "^2.3.0", + "vue-style-loader": "^4.1.0" + }, "devDependencies": { - "@babel/core": "^7.7.7", - "@babel/preset-env": "^7.11.5", - "@types/estree": "^0.0.45", - "@types/hash-sum": "^1.0.0", - "@types/jest": "^26.0.13", - "@types/jsdom": "^16.2.4", - "@types/loader-utils": "^2.0.1", - "@types/mini-css-extract-plugin": "^0.9.1", - "@types/webpack": "^4.41.0", - "@types/webpack-merge": "^4.1.5", - "@vue/compiler-sfc": "^3.0.8", - "babel-loader": "^8.1.0", - "cache-loader": "^4.1.0", - "conventional-changelog-cli": "^2.1.1", - "css-loader": "^4.3.0", - "file-loader": "^6.1.0", - "html-webpack-plugin": "^4.5.0", - "jest": "^26.4.1", - "jsdom": "^16.4.0", - "lint-staged": "^10.3.0", - "markdown-loader": "^6.0.0", + "@types/webpack": "^4.4.27", + "babel-core": "^6.26.0", + "babel-loader": "^7.1.4", + "babel-preset-env": "^1.6.1", + "cache-loader": "^2.0.1", + "conventional-changelog-cli": "^1.3.22", + "css-loader": "^1.0.0", + "eslint": "^4.19.0", + "eslint-plugin-vue-libs": "^2.1.0", + "file-loader": "^1.1.11", + "html-webpack-plugin": "4.0.0-beta.14", + "javascript-stringify": "^1.6.0", + "jest": "^23.5.0", + "jsdom": "^11.6.2", + "json": "^9.0.6", + "lint-staged": "^7.0.0", + "markdown-loader": "^2.0.2", "memfs": "^3.1.2", - "mini-css-extract-plugin": "^0.11.2", + "mini-css-extract-plugin": "^0.4.1", + "node-sass": "^4.7.2", "normalize-newline": "^3.0.0", - "null-loader": "^4.0.1", - "postcss-loader": "^4.0.4", - "prettier": "^2.1.1", - "pug": "^2.0.0", + "null-loader": "^0.1.1", + "postcss-loader": "^2.1.2", + "pug": "^2.0.1", "pug-plain-loader": "^1.0.0", - "source-map": "^0.6.1", - "style-loader": "^2.0.0", - "stylus": "^0.54.7", - "stylus-loader": "^4.1.1", - "sugarss": "^3.0.1", - "ts-jest": "^26.2.0", - "ts-loader": "^8.0.6", - "typescript": "^4.0.2", - "url-loader": "^4.1.0", - "vue": "^3.0.8", - "webpack": "^4.41.2", - "webpack-cli": "^3.3.10", - "webpack-dev-server": "^3.9.0", - "webpack-merge": "^5.1.4", - "webpack5": "npm:webpack@5", - "yorkie": "^2.0.0" + "raw-loader": "^0.5.1", + "sass-loader": "^6.0.7", + "source-map": "^0.5.0", + "stylus": "^0.54.5", + "stylus-loader": "^3.0.2", + "sugarss": "^1.0.1", + "ts-loader": "^4.2.0", + "typescript": "^3.9.5", + "url-loader": "^1.0.1", + "vue": "^2.5.16", + "vue-server-renderer": "^2.5.16", + "vue-template-compiler": "^2.5.16", + "vuepress": "^0.14.2", + "vuepress-theme-vue": "^1.1.0", + "webpack": "^4.1.0", + "webpack-cli": "^3.2.0", + "webpack-dev-server": "^3.1.1", + "webpack-merge": "^4.1.2", + "yorkie": "^1.0.3" } } diff --git a/packages/uni-cli-nvue/package.json b/packages/uni-cli-nvue/package.json index d4965e5f3..07b994b0b 100644 --- a/packages/uni-cli-nvue/package.json +++ b/packages/uni-cli-nvue/package.json @@ -22,9 +22,19 @@ "dependencies": { "@babel/core": "^7.14.8", "@babel/preset-env": "^7.14.8", + "@vue/component-compiler-utils": "^3.1.0", + "acorn": "^5.2.1", "babel-loader": "^8.2.2", + "css": "~2.2.1", + "de-indent": "^1.0.2", + "escodegen": "^1.8.1", + "hash-sum": "^1.0.2", + "he": "^1.1.0", + "loader-utils": "^1.1.0", "terser-webpack-plugin": "^5.1.4", - "vue-loader": "^16.3.3", + "vue-hot-reload-api": "^2.3.0", + "vue-loader": "^15.9.6", + "vue-style-loader": "^4.1.0", "webpack": "^5.45.1" }, "devDependencies": { diff --git a/packages/uni-cli-nvue/src/index.ts b/packages/uni-cli-nvue/src/index.ts index 85ec0d839..ecf3a8323 100644 --- a/packages/uni-cli-nvue/src/index.ts +++ b/packages/uni-cli-nvue/src/index.ts @@ -1 +1,4 @@ +/** + * 注意:该包的依赖包含了 lib 中的 vue-loader,weex-styler,weex-template-compiler + */ export * from './webpack' diff --git a/packages/uni-cli-nvue/src/webpack/config/module/rules/index.ts b/packages/uni-cli-nvue/src/webpack/config/module/rules/index.ts index 2c4a0c61c..5a1da09e0 100644 --- a/packages/uni-cli-nvue/src/webpack/config/module/rules/index.ts +++ b/packages/uni-cli-nvue/src/webpack/config/module/rules/index.ts @@ -1,18 +1,4 @@ import { RuleSetRule } from 'webpack' -export const rules: RuleSetRule[] = [ - { - test: [/\.nvue(\?[^?]+)?$/, /\.vue(\?[^?]+)?$/], - loader: 'vue-loader', - }, - { - test: /\.js$/, - use: [ - { - loader: 'babel-loader', - options: { - babelrc: false, - }, - }, - ], - }, -] +import { babelLoader } from './babelLoader' +import { vueLoader } from './vueLoader' +export const rules: RuleSetRule[] = [vueLoader, babelLoader] diff --git a/packages/uni-cli-nvue/src/webpack/config/optimization.ts b/packages/uni-cli-nvue/src/webpack/config/optimization.ts index 3071e98a6..6e5c2b5e8 100644 --- a/packages/uni-cli-nvue/src/webpack/config/optimization.ts +++ b/packages/uni-cli-nvue/src/webpack/config/optimization.ts @@ -2,6 +2,7 @@ import TerserPlugin from 'terser-webpack-plugin' import { Configuration } from 'webpack' export const optimization: Configuration['optimization'] = { + nodeEnv: false, // 禁用,由 define 统一设置 minimizer: [ new TerserPlugin({ terserOptions: { diff --git a/packages/uni-cli-nvue/src/webpack/config/plugins/vueLoader.ts b/packages/uni-cli-nvue/src/webpack/config/plugins/vueLoader.ts index 865152326..8b379c17e 100644 --- a/packages/uni-cli-nvue/src/webpack/config/plugins/vueLoader.ts +++ b/packages/uni-cli-nvue/src/webpack/config/plugins/vueLoader.ts @@ -1,2 +1,2 @@ -const { VueLoaderPlugin } = require('../../../../lib/vue-loader/dist') +const { VueLoaderPlugin } = require('../../../../lib/vue-loader') export const vueLoaderPlugin = new VueLoaderPlugin() diff --git a/packages/vite-plugin-uni/src/cli/action.ts b/packages/vite-plugin-uni/src/cli/action.ts index c3ca4e7ce..d240605be 100644 --- a/packages/vite-plugin-uni/src/cli/action.ts +++ b/packages/vite-plugin-uni/src/cli/action.ts @@ -29,7 +29,7 @@ export async function runDev(options: CliOptions & ServerOptions) { await build(extend(options, { watch: true })) } if (options.platform === 'app') { - await runNVue('prod') + await runNVue('dev') } } catch (e) { console.error(`error when starting dev server:\n${e.stack || e}`) @@ -44,7 +44,7 @@ export async function runBuild(options: CliOptions & BuildOptions) { ? buildSSR(options) : build(options)) if (options.platform === 'app') { - await runNVue('dev') + await runNVue('prod') } console.log(` DONE Build complete.`) } catch (e) { diff --git a/packages/vite-plugin-uni/tsconfig.json b/packages/vite-plugin-uni/tsconfig.json index d59e92c29..4f11ce016 100644 --- a/packages/vite-plugin-uni/tsconfig.json +++ b/packages/vite-plugin-uni/tsconfig.json @@ -6,7 +6,6 @@ "include": [ "src", "../shims-node.d.ts", - "../shims-uni-app.d.ts", - "../../node_modules/postcss/lib/postcss.d.ts" + "../shims-uni-app.d.ts" ] } -- GitLab