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

feat(cli): wxsCallMethods

上级 fd00be4d
......@@ -4,7 +4,7 @@ const {
const simplePathRE = /^[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*|\['[^']*?']|\["[^"]*?"]|\[\d+]|\[[A-Za-z_$][\w$]*])*$/
function processEvent(expr, filterModules) {
function processEvent (expr, filterModules) {
const isMethodPath = simplePathRE.test(expr)
if (isMethodPath) {
if (filterModules.find(name => expr.indexOf(name + '.') === 0)) {
......@@ -22,7 +22,7 @@ ${expr}
`
}
function hasOwn(obj, key) {
function hasOwn (obj, key) {
return hasOwnProperty.call(obj, key)
}
......@@ -33,7 +33,7 @@ const deprecated = {
}
}
function addTag(tag) {
function addTag (tag) {
if (!process.UNI_TAGS) {
process.UNI_TAGS = new Set()
}
......@@ -43,7 +43,7 @@ function addTag(tag) {
module.exports = {
preserveWhitespace: false,
modules: [require('../format-text'), {
preTransformNode(el, {
preTransformNode (el, {
warn
}) {
if (el.tag.indexOf('v-uni-') === 0) {
......@@ -53,7 +53,7 @@ module.exports = {
el.tag = 'v-uni-' + el.tag
}
},
postTransformNode(el, {
postTransformNode (el, {
warn,
filterModules
}) {
......
......@@ -10,7 +10,7 @@ const {
const WebpackHtmlAppendPlugin = require('../../packages/webpack-html-append-plugin')
function resolve(dir) {
function resolve (dir) {
return path.resolve(__dirname, '../../', dir)
}
......@@ -61,7 +61,7 @@ if (devServer && Object.keys(devServer).length) {
module.exports = {
vueConfig,
webpackConfig(webpackConfig) {
webpackConfig (webpackConfig) {
return {
devtool: process.env.NODE_ENV === 'production' ? false : 'source-map',
resolve: {
......@@ -100,7 +100,7 @@ module.exports = {
plugins
}
},
chainWebpack(webpackConfig) {
chainWebpack (webpackConfig) {
webpackConfig.plugins.delete('copy')
if (!process.env.UNI_OPT_PREFETCH) {
......
{
"name": "@dcloudio/vue-cli-plugin-uni",
"version": "0.9.528",
"version": "0.9.529",
"description": "uni-app plugin for vue-cli 3",
"main": "index.js",
"scripts": {
......
const path = require('path')
const loaderUtils = require('loader-utils')
const t = require('@babel/types')
const parser = require('@babel/parser')
const traverse = require('@babel/traverse').default
const {
normalizeNodeModules
} = require('@dcloudio/uni-cli-shared/lib/platform')
......@@ -18,10 +24,40 @@ module.exports = function(source, map) {
map
)
} else { // mp
const callMethods = new Set()
if (source.indexOf('callMethod') !== -1) {
traverse(parser.parse(source, {
sourceType: 'module'
}), {
MemberExpression(path, state) {
const property = path.node.property
const parentNode = path.parent
if (
(
property.name === 'callMethod' ||
property.value === 'callMethod'
) &&
t.isCallExpression(parentNode) &&
t.isLiteral(parentNode.arguments[0])
) {
callMethods.add(parentNode.arguments[0].value)
}
}
})
}
if (params.issuerPath) {
const resourcePath = normalizeNodeModules(path.relative(process.env.UNI_INPUT_DIR, this.resourcePath))
this.emitFile(resourcePath, source)
}
this.callback(null, `export default {}`, map)
this.callback(null,
`export default function (Component) {
if(!Component.options.wxsCallMethods){
Component.options.wxsCallMethods = []
}
${[...callMethods].map(method=>{
return "Component.options.wxsCallMethods.push('"+method+"')"
}).join('\n')}
}`,
map)
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册