vant icon indicating copy to clipboard operation
vant copied to clipboard

是否有 ts-import-plugin 的vant配置示例?

Open hemiaoio opened this issue 8 years ago • 3 comments

IMPORTANT: Please use the following link to create a new issue. If your issue was not created using the app above, it will be closed immediately.

Packages version: Vue 2.5.17 Vue-Cli 3.0.4 Vant 1.3.3 ts-import-plugin 1.5.5

What problem does this feature solve? 我按照文档上的教程仿着配置了一个ts-import-plugin,但是 cli build --report 出来的文件看到还是全部组件都引入了。libraryDirectory 从 es 换成 lib 还是同样的效果。 _20180929222159

components.vue

// 使用这种方式是有效果的
// import Dialog from 'vant/lib/dialog/index.js';

// 使用这种方式并没有达到按需引入目的
import { Dialog } from 'vant';

vue.config.js

module.exports = {
    lintOnSave: false,
    baseUrl: process.env.BASE_URL,
    css: {
        modules: false,
    },

    configureWebpack: {
        module: {
            rules: [{
                    test: /\.(jsx|tsx|js|ts)$/,
                    loader: 'ts-loader',
                    options: {
                        happyPackMode: true,
                        transpileOnly: true,
                        getCustomTransformers: () => ({
                            before: [tsImportPluginFactory({
                                libraryName: 'vant',
                                libraryDirectory: 'lib',  // or es 但是效果一样。
                                style: true
                            })]
                        }),
                        compilerOptions: {
                            module: 'es2015'
                        }
                    },
                }
            ]
        }
    },
    devServer: {
        disableHostCheck: true
    }
}

Describe the solution you'd like 求教一个正确的tsImportPluginFactory() 配置方法。

What does the proposed API look like? _20180929223318

hemiaoio avatar Sep 29 '18 14:09 hemiaoio

建议去 ts-import-plugin 下提问,Vant 配置和其他库是一样的

chenjiahan avatar Oct 02 '18 00:10 chenjiahan

这个问题有解决么? @hemiaoio

Mrlilili avatar Jan 22 '19 11:01 Mrlilili

https://github.com/youzan/vant-demo 有ts的示例

victorwang0526 avatar Dec 05 '19 08:12 victorwang0526