tua-mp icon indicating copy to clipboard operation
tua-mp copied to clipboard

请问如何引入原生自定义组件?

Open dannnney opened this issue 7 years ago • 1 comments

请问如何引入原生自定义组件? 谢谢

dannnney avatar Nov 16 '18 06:11 dannnney

这个问题本质上是把已有的原生自定义组件【复制】到 dist/ 目录中,假设这些组件放在 src/foobar/ 目录下,需要拷贝到 dist/foobar/ 下。可以在 tua-mp.config.js 这样写:

// tua-mp.config.js
module.exports = {
    chainWebpack: (config) => {
        config
            .plugin('copy-webpack-plugin')
            .tap(([ patterns, ...rest ]) => ([
                [
                    ...patterns,
                    
                    // 小程序组件目录
                    { from: 'foobar/', to: 'foobar/' },
                ],
                ...rest,
            ]))
    },
}

假设其中有某个组件叫做 Dialog,之后在页面、组件里引入路径就是这样

{
    "usingComponents": {
        "Dialog": "/foobar/Dialog/Dialog"
    },
}

回头补一下文档和示例...

BuptStEve avatar Nov 16 '18 09:11 BuptStEve