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

feat(cli): wxsCallMethods

上级 fd00be4d
...@@ -4,7 +4,7 @@ const { ...@@ -4,7 +4,7 @@ const {
const simplePathRE = /^[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*|\['[^']*?']|\["[^"]*?"]|\[\d+]|\[[A-Za-z_$][\w$]*])*$/ 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) const isMethodPath = simplePathRE.test(expr)
if (isMethodPath) { if (isMethodPath) {
if (filterModules.find(name => expr.indexOf(name + '.') === 0)) { if (filterModules.find(name => expr.indexOf(name + '.') === 0)) {
...@@ -22,7 +22,7 @@ ${expr} ...@@ -22,7 +22,7 @@ ${expr}
` `
} }
function hasOwn(obj, key) { function hasOwn (obj, key) {
return hasOwnProperty.call(obj, key) return hasOwnProperty.call(obj, key)
} }
...@@ -33,7 +33,7 @@ const deprecated = { ...@@ -33,7 +33,7 @@ const deprecated = {
} }
} }
function addTag(tag) { function addTag (tag) {
if (!process.UNI_TAGS) { if (!process.UNI_TAGS) {
process.UNI_TAGS = new Set() process.UNI_TAGS = new Set()
} }
...@@ -43,7 +43,7 @@ function addTag(tag) { ...@@ -43,7 +43,7 @@ function addTag(tag) {
module.exports = { module.exports = {
preserveWhitespace: false, preserveWhitespace: false,
modules: [require('../format-text'), { modules: [require('../format-text'), {
preTransformNode(el, { preTransformNode (el, {
warn warn
}) { }) {
if (el.tag.indexOf('v-uni-') === 0) { if (el.tag.indexOf('v-uni-') === 0) {
...@@ -53,7 +53,7 @@ module.exports = { ...@@ -53,7 +53,7 @@ module.exports = {
el.tag = 'v-uni-' + el.tag el.tag = 'v-uni-' + el.tag
} }
}, },
postTransformNode(el, { postTransformNode (el, {
warn, warn,
filterModules filterModules
}) { }) {
......
...@@ -10,7 +10,7 @@ const { ...@@ -10,7 +10,7 @@ const {
const WebpackHtmlAppendPlugin = require('../../packages/webpack-html-append-plugin') const WebpackHtmlAppendPlugin = require('../../packages/webpack-html-append-plugin')
function resolve(dir) { function resolve (dir) {
return path.resolve(__dirname, '../../', dir) return path.resolve(__dirname, '../../', dir)
} }
...@@ -61,7 +61,7 @@ if (devServer && Object.keys(devServer).length) { ...@@ -61,7 +61,7 @@ if (devServer && Object.keys(devServer).length) {
module.exports = { module.exports = {
vueConfig, vueConfig,
webpackConfig(webpackConfig) { webpackConfig (webpackConfig) {
return { return {
devtool: process.env.NODE_ENV === 'production' ? false : 'source-map', devtool: process.env.NODE_ENV === 'production' ? false : 'source-map',
resolve: { resolve: {
...@@ -100,7 +100,7 @@ module.exports = { ...@@ -100,7 +100,7 @@ module.exports = {
plugins plugins
} }
}, },
chainWebpack(webpackConfig) { chainWebpack (webpackConfig) {
webpackConfig.plugins.delete('copy') webpackConfig.plugins.delete('copy')
if (!process.env.UNI_OPT_PREFETCH) { if (!process.env.UNI_OPT_PREFETCH) {
......
{ {
"name": "@dcloudio/vue-cli-plugin-uni", "name": "@dcloudio/vue-cli-plugin-uni",
"version": "0.9.528", "version": "0.9.529",
"description": "uni-app plugin for vue-cli 3", "description": "uni-app plugin for vue-cli 3",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {
......
const path = require('path') const path = require('path')
const loaderUtils = require('loader-utils') const loaderUtils = require('loader-utils')
const t = require('@babel/types')
const parser = require('@babel/parser')
const traverse = require('@babel/traverse').default
const { const {
normalizeNodeModules normalizeNodeModules
} = require('@dcloudio/uni-cli-shared/lib/platform') } = require('@dcloudio/uni-cli-shared/lib/platform')
...@@ -18,10 +24,40 @@ module.exports = function(source, map) { ...@@ -18,10 +24,40 @@ module.exports = function(source, map) {
map map
) )
} else { // mp } 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) { if (params.issuerPath) {
const resourcePath = normalizeNodeModules(path.relative(process.env.UNI_INPUT_DIR, this.resourcePath)) const resourcePath = normalizeNodeModules(path.relative(process.env.UNI_INPUT_DIR, this.resourcePath))
this.emitFile(resourcePath, source) 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.
先完成此消息的编辑!
想要评论请 注册