提交 4d9f08fd 编写于 作者: fxy060608's avatar fxy060608

Merge branch 'dev' of https://github.com/dcloudio/uni-app into alpha

......@@ -8,11 +8,15 @@ 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('@hap-toolkit/dsl-vue/lib/plugin/instvue-plugin')
const InstMainPlugin = require('./plugin/main-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
......@@ -23,14 +27,9 @@ const env = {
const dslFilename = ('vue.' + (process.env.NODE_ENV === 'production' ? 'prod' : 'dev') + '.js')
parseManifest(process.UNI_PAGES, process.UNI_MANIFEST)
const manifest = global.framework.manifest
if (!manifest.package) {
console.error(`maniest.json quickapp 节点缺少 package 配置`)
process.exit(0)
}
function genPriorities(entryPagePath) {
const o = [/^i18n\/.+\.json$/i, 'manifest.json', 'app.js', /^common\//i];
......@@ -74,7 +73,6 @@ module.exports = {
new HandlerPlugin({}),
new Css2jsonPlugin(),
new InstVuePlugin(),
new InstMainPlugin(),
new ZipPlugin({
name: manifest.package,
icon: manifest.icon,
......
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;
`
......
......@@ -16,6 +16,10 @@ 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 = {}
}
......
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 => {
entry[page.path] = path.resolve(process.env.UNI_INPUT_DIR, page.path + '.vue?uxType=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
}
......@@ -4,14 +4,39 @@ const parseDisplay = require('./display-parser')
const parseEntry = require('./entry-parser')
function getPages(pagesJson) {
const ret = pagesJson.pages
const subPackages = pagesJson.subPackages
if (!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 || {}
parseBase(manifest, manifestJson)
parsePages(manifest, pagesJson.pages)
parseDisplay(manifest, pagesJson.pages, pagesJson.globalStyle)
process.UNI_ENTRY = parseEntry(pagesJson.pages)
const pages = getPages(pagesJson)
parsePages(manifest, pages)
parseDisplay(manifest, pages, pagesJson.globalStyle)
process.UNI_ENTRY = parseEntry(pages)
global.framework.manifest = manifest
......
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
const WebpackSources = require('webpack-sources')
class InstMainPlugin {
apply(compiler) {
compiler.hooks.compilation.tap('InstMainPlugin', (compilation) => {
compilation.hooks.optimizeChunkAssets.tapAsync('InstMainPlugin', (chunks, callback) => {
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 })();`
)
}
callback()
})
})
}
}
module.exports = InstMainPlugin
div {
flex-direction: column;
}
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->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)
}
}
......@@ -8,21 +8,24 @@ module.exports = (api, options, rootOptions) => {
scripts: {
'info': 'node node_modules/@dcloudio/vue-cli-plugin-uni/commands/info.js',
'serve': 'npm run dev:h5',
'build': 'npm run build:h5',
'build': 'npm run build:h5',
'serve:quickapp': 'node node_modules/@dcloudio/uni-quickapp/bin/serve.js',
'dev:h5': 'cross-env NODE_ENV=development UNI_PLATFORM=h5 vue-cli-service uni-serve',
'dev:mp-qq': 'cross-env NODE_ENV=development UNI_PLATFORM=mp-qq vue-cli-service uni-build --watch',
'dev:mp-weixin': 'cross-env NODE_ENV=development UNI_PLATFORM=mp-weixin vue-cli-service uni-build --watch',
'dev:mp-baidu': 'cross-env NODE_ENV=development UNI_PLATFORM=mp-baidu vue-cli-service uni-build --watch',
'dev:mp-alipay': 'cross-env NODE_ENV=development UNI_PLATFORM=mp-alipay vue-cli-service uni-build --watch',
'dev:mp-toutiao': 'cross-env NODE_ENV=development UNI_PLATFORM=mp-toutiao vue-cli-service uni-build --watch',
'dev:mp-360': 'cross-env NODE_ENV=development UNI_PLATFORM=mp-360 vue-cli-service uni-build --watch',
'dev:quickapp': 'cross-env NODE_ENV=development UNI_PLATFORM=quickapp vue-cli-service uni-build --watch',
'dev:mp-360': 'cross-env NODE_ENV=development UNI_PLATFORM=mp-360 vue-cli-service uni-build --watch',
'build:h5': 'cross-env NODE_ENV=production UNI_PLATFORM=h5 vue-cli-service uni-build',
'build:mp-qq': 'cross-env NODE_ENV=production UNI_PLATFORM=mp-qq vue-cli-service uni-build',
'build:mp-weixin': 'cross-env NODE_ENV=production UNI_PLATFORM=mp-weixin vue-cli-service uni-build',
'build:mp-baidu': 'cross-env NODE_ENV=production UNI_PLATFORM=mp-baidu vue-cli-service uni-build',
'build:mp-alipay': 'cross-env NODE_ENV=production UNI_PLATFORM=mp-alipay vue-cli-service uni-build',
'build:mp-toutiao': 'cross-env NODE_ENV=production UNI_PLATFORM=mp-toutiao vue-cli-service uni-build',
'build:mp-360': 'cross-env NODE_ENV=production UNI_PLATFORM=mp-360 vue-cli-service uni-build',
'build:quickapp': 'cross-env NODE_ENV=production UNI_PLATFORM=quickapp vue-cli-service uni-build',
'build:mp-360': 'cross-env NODE_ENV=production UNI_PLATFORM=mp-360 vue-cli-service uni-build',
'dev:custom': 'cross-env NODE_ENV=development uniapp-cli custom',
'build:custom': 'cross-env NODE_ENV=production uniapp-cli custom'
},
......
......@@ -280,7 +280,7 @@ let hasNVue = false
if (process.env.UNI_USING_NATIVE) {
console.log('当前nvue编译模式:' + (isNVueCompiler ? 'uni-app' : 'weex') +
' 。编译模式差异见:https://ask.dcloud.net.cn/article/36074')
} else if (process.env.UNI_PLATFORM !== 'h5') {
} else if (process.env.UNI_PLATFORM !== 'h5' && process.env.UNI_PLATFORM !== 'quickapp') {
try {
let info = ''
if (process.env.UNI_PLATFORM === 'app-plus') {
......
......@@ -17,7 +17,15 @@ Vue.prototype.$mount = function () {}
Vue.config = {}
Vue.use = function (plugin) {
plugins.push(plugin)
const isVuex = plugin.Store && plugin.mapState
if (isVuex) {
const exports = {}
/* eslint-disable no-undef */
context.VueFactory(exports, {} /* document */, {} /* quickappHelper */)
plugin.install(exports.Vue)
} else {
plugins.push(plugin)
}
}
Vue.mixin = function (mixin) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册