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

feat(qa): add main-loader

上级 12e80116
......@@ -10,6 +10,8 @@ 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 parseManifest = require('./manifest/index')
const env = {
......@@ -46,6 +48,15 @@ module.exports = {
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
......@@ -63,6 +74,7 @@ module.exports = {
new HandlerPlugin({}),
new Css2jsonPlugin(),
new InstVuePlugin(),
new InstMainPlugin(),
new ZipPlugin({
name: manifest.package,
icon: manifest.icon,
......
//import uni-pages
//解析main.js中全局组件?
module.exports = function(source, map) {
return `
import 'uni-pages';
${source}
export default App;
`
}
const path = require('path')
module.exports = function parseEntry(pages) {
const entry = {
'app': path.resolve(process.env.UNI_INPUT_DIR, 'App.vue?uxType=app')
'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 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
// 目前仅支持 store, use, mixin, component
// 目前仅支持 store, use, mixin, component, prototype
let store
const mixins = []
const plugins = []
const components = []
// fake
function Vue (options) {
if (options && options.store) {
store = options.store
}
}
Vue.prototype.$mount = function () {}
Vue.config = {}
Vue.use = function (plugin) {
plugins.push(plugin)
}
......@@ -29,23 +34,29 @@ Vue.component = function (id, definition) {
const injectRef = Object.getPrototypeOf(global) || global
injectRef.__VuePlugin = {
install (Vue, options) {
install (PageVue, options) {
mixins.forEach(mixin => {
Vue.mixin(mixin)
PageVue.mixin(mixin)
})
plugins.forEach(plugin => {
Vue.use(plugin)
PageVue.use(plugin)
})
components.forEach(({
id,
definition
}) => {
Vue.component(id, definition)
PageVue.component(id, definition)
})
Object.keys(Vue.prototype).forEach(name => {
if (name !== '$mount') {
PageVue.prototype[name] = Vue.prototype[name]
}
})
store && (Vue.prototype.$store = store)
store && (PageVue.prototype.$store = store)
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册