提交 31ed94ab 编写于 作者: fxy060608's avatar fxy060608

feat(qa): nvue

上级 96419591
......@@ -8,9 +8,8 @@ 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')
......@@ -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;
`
......
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;
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册