智能照明系统APP-本地串口
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
LightingSystemApp-serial/.svn/pristine/56/56c5a5338a9e23ef073831e78c3...

61 lines
1.4 KiB

const {
jsPreprocessOptions
} = require('@dcloudio/uni-cli-shared')
const preprocessor = require('@dcloudio/vue-cli-plugin-uni/packages/webpack-preprocess-loader/preprocess')
const traverse = require('@dcloudio/webpack-uni-mp-loader/lib/babel/scoped-component-traverse')
const {
parseComponents
} = require('./util')
function genComponentCode (components) {
const importCode = []
const componentsCode = []
components.forEach(({
name,
value,
source
}) => {
importCode.push(`import ${value} from '${source}'`)
componentsCode.push(`'${name}': ${value}`)
})
return [importCode.join('\n'), componentsCode.join(',\n')]
}
function genCode ({
components,
options
}, css = []) {
const optionsCode = []
Object.keys(options).forEach(name => {
options[name] !== null && optionsCode.push(`${name}:${options[name]}`)
})
const [importComponentCode, componentsCode] = genComponentCode(components)
// TODO js 内引用 css
return `
${importComponentCode}
export default {
${optionsCode.length ? (optionsCode.join(',') + ',') : ''}
data(){
return {
wxsProps:{}
}
},
components:{
${componentsCode}
}
}
`
}
module.exports = function (content, map) {
this.cacheable && this.cacheable()
content = preprocessor.preprocess(content, jsPreprocessOptions.context, {
type: jsPreprocessOptions.type
})
this.callback(null, genCode(parseComponents(content, traverse)), map)
}