【问题标题】:Vuejs 3 - what's the alternative of require.context in vitejsVuejs 3 - vitejs 中 require.context 的替代方案是什么
【发布时间】:2021-04-18 06:38:15
【问题描述】:

我正在寻找在 vitejs 中创建与 webpack 的 require.context 相同逻辑的方法,我找到了这个名为 vite-plugin-import-context 的插件,我尝试了一下,但有一些我不明白的东西是 @ 987654323@中的基本用法:

import { UserConfigExport } from 'vite';
import vue from '@vitejs/plugin-vue';

import dynamicImport from '../src/index';// <-- this is not described

export default (): UserConfigExport => {
  return {
    plugins: [vue(), dynamicImport(/*options*/)],
  };
};

【问题讨论】:

    标签: vue.js webpack vuejs3 vite


    【解决方案1】:

    import.meta.glob() 是 webpack 替代 require.context() 。从 v2.3.4 开始在 vite 中添加。

    这里是文档https://vitejs.dev/guide/features.html#glob-import的链接

    【讨论】:

      【解决方案2】:

      是的,该示例直接取自 examples folder in the repo,因此它仅适用于该存储库。

      如果您通过 npm 或 yarn 安装插件,该行应类似于 import dynamicImport from 'vite-plugin-import-context'

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-11-13
        • 2018-12-01
        • 1970-01-01
        • 1970-01-01
        • 2018-11-29
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多