Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: (0 , import_vite_plugin_html.default) is not a function #146

Open
dongfangmeng opened this issue Feb 26, 2024 · 1 comment
Open

Comments

@dongfangmeng
Copy link

"devDependencies": {
"@vitejs/plugin-vue": "3.1.0",
"@vue/compiler-sfc": "3.2.45",
"sass": "1.56.1",
"unplugin-auto-import": "0.11.4",
"vite": "3.2.3",
"vite-plugin-compression": "0.5.1",
"vite-plugin-html": "^3.2.2",
"vite-plugin-svg-icons": "2.0.1",
"vite-plugin-vue-setup-extend": "0.4.0"
} node版本16.14.0 报错如下TypeError: (0 , import_vite_plugin_html.default) is not a function
at createVitePlugins (D:\projects\ls-zhsw\ls-bigscreen\vite.config.js:120:56)
at D:\projects\ls-zhsw\ls-bigscreen\vite.config.js:136:14
at loadConfigFromFile (file:///D:/projects/ls-zhsw/ls-bigscreen/node_modules/vite/dist/node/chunks/dep-51c4f80a.js:62715:15)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async resolveConfig (file:///D:/projects/ls-zhsw/ls-bigscreen/node_modules/vite/dist/node/chunks/dep-51c4f80a.js:62336:28)
at async doBuild (file:///D:/projects/ls-zhsw/ls-bigscreen/node_modules/vite/dist/node/chunks/dep-51c4f80a.js:45244:20)
at async build (file:///D:/projects/ls-zhsw/ls-bigscreen/node_modules/vite/dist/node/chunks/dep-51c4f80a.js:45233:16)
at async CAC. (file:///D:/projects/ls-zhsw/ls-bigscreen/node_modules/vite/dist/node/cli.js:756:9)

@dongfangmeng
Copy link
Author

import html from 'vite-plugin-html'
export default function createVitePlugins(viteEnv, isBuild = false) {
const vitePlugins = [vue()]

 // 创建html插件实例并配置transform选项
 const htmlPluginConfig = {
    inject: false, // 如果需要自定义index.html,设置为false
    transform: (html, ctx) => {
        return html.replace(
          /(<script [^>]*libpath=")([^"]+)"/g,
          (_, prefix, libPath) => {
            return `${prefix}${process.env.NODE_ENV === 'production' ? '/bigscene/' : ''}${libPath}`;
          }
        ).replace(
          /(<script [^>]*src=")([^"]+)"/g,
          (_, prefix, src) => {
            const matchLibPath = src.match(/(.*\/hy-mars\/lib\/)/);
            if (matchLibPath) {
              const libPath = matchLibPath[1];
              return `${prefix}${process.env.NODE_ENV === 'production' ? '/bigscene/' : ''}${src}`;
            }
            return prefix + src;
          }
        );
    },
};
vitePlugins.push(html(htmlPluginConfig));

return vitePlugins
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant