first commit

This commit is contained in:
2026-09-08 20:28:54 +08:00
commit 2ada8d3d5a
37380 changed files with 4886169 additions and 0 deletions
+28
View File
@@ -0,0 +1,28 @@
const vueLoader = require('@dcloudio/uni-cli-shared/lib/vue-loader')
module.exports = config => {
config.module
.rule('vue')
.test(vueLoader.test)
.use('vue-loader')
.loader(vueLoader.loader)
.tap(options => Object.assign(options, vueLoader.options({}, {
'quickapp-native': true
})))
config.module
.rule('vue')
.uses
.delete('cache-loader')
config.plugin('extract-css')
.init((Plugin, args) => new Plugin({
filename: '[name].css.json'
}))
config.plugins.delete('hmr')
config.plugins.delete('html')
config.plugins.delete('copy')
config.plugins.delete('preload')
config.plugins.delete('prefetch')
}
+7
View File
@@ -0,0 +1,7 @@
module.exports = {
preTransformNode (el) {
if (el.tag === 'view') { // view 是最常用组件,直接映射为div标签,保证性能
el.tag = 'div'
}
}
}
+107
View File
@@ -0,0 +1,107 @@
const path = require('path')
const webpack = require('webpack')
const CopyPlugin = require('copy-webpack-plugin')
const CopyPluginVersion = Number(require('copy-webpack-plugin/package.json').version.split('.')[0])
const HandlerPlugin = require('@hap-toolkit/packager/lib/plugin/handler-plugin')
const ZipPlugin = require('@hap-toolkit/packager/lib/plugin/zip-plugin')
const NotifyPlugin = require('@hap-toolkit/packager/lib/plugin/notify-plugin')
const Css2jsonPlugin = require('@hap-toolkit/dsl-vue/lib/plugin/css2json-plugin')
const InstVuePlugin = require('./plugin/instvue-plugin')
const parseManifest = require('./manifest/index')
const validate = require('./validate')
parseManifest(process.UNI_PAGES, process.UNI_MANIFEST)
validate()
const env = {
// 平台:native
NODE_PLATFORM: 'native',
// 阶段: dev|test|release
NODE_PHASE: process.env.NODE_PHASE
}
const dslFilename = ('vue.' + (process.env.NODE_ENV === 'production' ? 'prod' : 'dev') + '.js')
const manifest = global.framework.manifest
function genPriorities (entryPagePath) {
const o = [/^i18n\/.+\.json$/i, 'manifest.json', 'app.js', /^common\//i]
if (entryPagePath) {
o.splice(3, 0, new RegExp(`^${entryPagePath}/$`), new RegExp(`^${entryPagePath}/.+`))
} else console.error('未配置入口页面')
return o
}
const uniCloudPath = require.resolve('@dcloudio/vue-cli-plugin-uni/packages/uni-cloud/dist/index.js')
const patterns = [{
from: path.resolve(__dirname, '../dist/' + dslFilename),
to: 'dsl.js'
}]
module.exports = {
devtool: false,
entry () {
return process.UNI_ENTRY
},
output: {
filename: '[name].js',
chunkFilename: '[name].js'
},
optimization: {
splitChunks: false,
runtimeChunk: false
},
externals: {
vue: 'Vue'
},
module: {
rules: [{
// 暂不考虑ts
test: path.resolve(process.env.UNI_INPUT_DIR, 'main.js'),
use: [{
loader: path.resolve(__dirname, 'loader/main-loader')
}]
}]
},
plugins: [
new webpack.DefinePlugin({
// 平台:na
ENV_PLATFORM: JSON.stringify(env.NODE_PLATFORM),
// 阶段: dev|test|release
ENV_PHASE: JSON.stringify(env.NODE_PHASE),
ENV_PHASE_DV: env.NODE_PHASE === 'dev',
ENV_PHASE_QA: env.NODE_PHASE === 'test',
ENV_PHASE_OL: env.NODE_PHASE === 'prod'
}),
new webpack.ProvidePlugin({
uniCloud: [uniCloudPath, 'uniCloud']
}),
new CopyPlugin(CopyPluginVersion > 5 ? { patterns } : patterns),
new HandlerPlugin({}),
new Css2jsonPlugin(),
new InstVuePlugin(),
new ZipPlugin({
name: manifest.package,
icon: manifest.icon,
versionCode: manifest.versionCode,
output: path.resolve(process.env.UNI_OUTPUT_DIR, '..'),
pathBuild: process.env.UNI_OUTPUT_DIR,
pathSignFolder: './sign',
sign: process.env.NODE_ENV === 'production' ? 'release' : 'debug',
priorities: genPriorities(manifest.router.entry),
subpackages: undefined,
comment: '',
cwd: process.env.UNI_INPUT_DIR,
disableStreamPack: undefined,
disableSubpackages: undefined
}),
new NotifyPlugin()
]
}
+15
View File
@@ -0,0 +1,15 @@
const path = require('path')
const isWin = /^win/.test(process.platform)
const normalizePath = path => (isWin ? path.replace(/\\/g, '/') : path)
const polyfill = normalizePath(path.resolve(__dirname, '../polyfill.css'))
module.exports = function(source, map) {
return `
import 'uni-pages';
import '${polyfill}';
${source}
export default App;
`
}
+32
View File
@@ -0,0 +1,32 @@
const ATTRS = {
'name': 'name',
'versionName': 'versionName',
'versionCode': 'versionCode'
}
function merge(to, from) {
Object.keys(ATTRS).forEach(name => {
if (!to[name]) {
to[name] = from[name]
}
})
}
module.exports = function parseBase(manifest, manifestJson) {
merge(manifest, manifestJson)
manifest.versionCode = parseInt(manifest.versionCode) || 1
if (!manifest.package) {
manifest.package = manifest.name || 'Bundle'
}
if (!manifest.config) {
manifest.config = {}
}
if (!manifest.config.dsl) {
manifest.config.dsl = {}
}
manifest.config.dsl.name = 'vue'
return manifest
}
@@ -0,0 +1,67 @@
const PLATFORMS = [
'h5',
'app-plus',
'mp-weixin',
'mp-qq',
'mp-baidu',
'mp-alipay',
'mp-jd',
'mp-xhs',
'mp-toutiao',
'quickapp-native'
]
const DISPLAY = {
'navigationBarBackgroundColor': 'titleBarBackgroundColor',
'navigationBarTextStyle': (style, val) => {
if (val === 'black') {
style.titleBarTextColor = '#000000'
style.statusBarTextStyle = 'dark'
} else {
style.titleBarTextColor = '#ffffff'
style.statusBarTextStyle = 'light'
}
},
'navigationBarTitleText': 'titleBarText',
'navigationStyle': (style, val) => {
if (val === 'custom') {
style.titleBar = false
}
}
}
function parseStyle(style = {}) {
const ret = {}
Object.keys(style).forEach(name => {
if (!PLATFORMS.includes(name)) {
const transform = DISPLAY[name]
if (transform) {
if (typeof transform === 'string') {
ret[transform] = style[name]
} else if (typeof transform === 'function') {
transform(ret, style[name])
}
} else {
ret[name] = style[name]
}
}
})
if (style['quickapp-native']) {
Object.assign(ret, style['quickapp-native'])
}
return ret
}
module.exports = function parseDisplay(manifest, pages, globalStyle = {}) {
const display = {
pages: {}
}
// globalStyle
Object.assign(display, parseStyle(globalStyle))
pages.forEach(page => {
const key = page.path.substr(0, page.path.lastIndexOf('/'))
display.pages[key] = parseStyle(page.style)
})
manifest.display = display
}
@@ -0,0 +1,16 @@
const fs = require('fs')
const path = require('path')
module.exports = function parseEntry(pages) {
const entry = {
'app': path.resolve(process.env.UNI_INPUT_DIR, 'main.js')
}
pages.forEach(page => {
const filepath = path.resolve(process.env.UNI_INPUT_DIR, page.path)
if (fs.existsSync(filepath + '.nvue')) {
entry[page.path] = filepath + '.nvue?uxType=page'
} else {
entry[page.path] = filepath + '.vue?uxType=page'
}
})
return entry
}
+46
View File
@@ -0,0 +1,46 @@
const parseBase = require('./base-parser')
const parsePages = require('./pages-parser')
const parseDisplay = require('./display-parser')
const parseEntry = require('./entry-parser')
function getPages(pagesJson) {
const ret = pagesJson.pages
const subPackages = pagesJson.subPackages
if (!subPackages || !subPackages.length) {
return ret
}
subPackages.forEach(({
root,
pages
}) => {
if (!Array.isArray(pages)) {
return
}
pages.forEach(page => {
page.path = root + '/' + page.path
ret.push(page)
})
})
return ret
}
module.exports = function(pagesJson, manifestJson, loader) {
const manifest = manifestJson['quickapp-native'] || {}
parseBase(manifest, manifestJson)
const pages = getPages(pagesJson)
parsePages(manifest, pages)
parseDisplay(manifest, pages, pagesJson.globalStyle)
process.UNI_ENTRY = parseEntry(pages)
global.framework.manifest = manifest
loader && loader.emitFile('manifest.json', JSON.stringify(manifest))
return ''
}
@@ -0,0 +1,15 @@
module.exports = function parsePages(manifest, pages) {
const entryPagePath = pages[0].path
const router = {
entry: entryPagePath.substr(0, entryPagePath.lastIndexOf('/')),
pages: {}
}
pages.forEach(page => {
const lastIndex = page.path.lastIndexOf('/')
const key = page.path.substr(0, lastIndex)
router.pages[key] = {
component: page.path.substr(lastIndex + 1)
}
})
manifest.router = router
}
@@ -0,0 +1,45 @@
const path = require('path')
const WebpackSources = require('webpack-sources')
const extList = ['.vue', '.nvue']
class InstVuePlugin {
apply(compiler) {
compiler.hooks.compilation.tap('InstVuePlugin', (compilation) => {
compilation.hooks.optimizeChunkAssets.tapAsync('InstVuePlugin', (chunks, callback) => {
this.instMain(compilation, chunks)
this.instVue(compilation, chunks)
callback()
})
})
}
instMain(compilation, chunks) {
if (chunks.find(chunk => chunk.files.includes('app.js'))) {
const appAsset = compilation.assets['app.js']
compilation.assets['app.js'] =
new WebpackSources.ConcatSource(
`(function(){\n var handler = function() {\n return `, appAsset,
`\n };\n if (typeof window === "undefined") {\n let options = handler();\n options.default['manifest'] = ${JSON.stringify(global.framework.manifest)}\n $app_define$(options.default)\n $app_bootstrap$()\n }\n })();`
)
}
}
instVue(compilation, chunks) {
chunks.forEach(chunk => {
const extname = path.extname(Array.from(chunk.entryModule.buildInfo.fileDependencies)[0])
if (!extList.includes(extname)) {
return
}
chunk.files.forEach(file => {
if (!/\.js$/.test(file)) {
return
}
compilation.assets[file] = new WebpackSources.ConcatSource(
`(function(){\n var handler = function() {\n return `,
compilation.assets[file],
`\n };\n if (typeof window === \"undefined\") {\n let options = handler();\n options = options.default ? options.default: options\n options['type'] = 'page'\n new Vue({render: function(h) {return h(options)}}).$mount('#app')\n }\n })();`
)
})
})
}
}
module.exports = InstVuePlugin
+3
View File
@@ -0,0 +1,3 @@
div {
flex-direction: column;
}
+11
View File
@@ -0,0 +1,11 @@
module.exports = {
options: {
cssVars: {
'--status-bar-height': '25px',
'--window-top': '0px',
'--window-bottom': '0px',
'--window-left': '0px',
'--window-right': '0px'
}
}
}
+24
View File
@@ -0,0 +1,24 @@
const fs = require('fs')
const path = require('path')
module.exports = function () {
const manifest = global.framework.manifest
if (manifest.package === 'Bundle') {
console.error('> 建议配置 manifest.json->quickapp-native->package 应用包名')
}
const signPath = './sign/' + (process.env.NODE_ENV === 'production' ? 'release' : 'debug')
const privatePemPath = path.resolve(process.env.UNI_INPUT_DIR, signPath + '/private.pem')
const certificatePemPath = path.resolve(process.env.UNI_INPUT_DIR, signPath + '/certificate.pem')
if (!fs.existsSync(privatePemPath)) {
console.error(`> 缺少私钥文件, 打包失败: ${privatePemPath}`)
process.exit(0)
}
if (!fs.existsSync(certificatePemPath)) {
console.error(`> 缺少证书文件, 打包失败: ${certificatePemPath}`)
process.exit(0)
}
}
+9
View File
@@ -0,0 +1,9 @@
global.framework = {}
const chainWebpack = require('./chain-webpack')
const configureWebpack = require('./configure-webpack')
module.exports = {
chainWebpack,
configureWebpack
}