vue-cli4-config
                                
                                 vue-cli4-config copied to clipboard
                                
                                    vue-cli4-config copied to clipboard
                            
                            
                            
                        cdn vue3 提示 Vue is not undefined
// cdn预加载使用 const externals = { 'vue': 'Vue', // 与这个'Vue'的写法有关吗?Vue3不暴露Vue了,而是createApp }
打包时,注释掉:// import { createApp } from 'vue';
将 const app = createApp(); 改成 const app = Vue.createApp(App); 即可
打包时,注释掉:
// import { createApp } from 'vue';将const = app = createApp();改成const app = Vue.createApp(App);即可
可以写一下你的代码么
打包时,注释掉:
// import { createApp } from 'vue';将const = app = createApp();改成const app = Vue.createApp(App);即可可以写一下你的代码么
[main.js]
import { createApp } from 'vue';
import App from './App.vue';
const app = createApp(App);
// const app = Vue.createApp(App);
app.mount('#app');
[vue.config.js]
const isProd = process.env.NODE_ENV === 'production';
module.exports = {
    chainWebpack: config => {
        config.plugin('html').tap(args => {
            if (isProd) {
                args[0].cdn = {
                    css: [],
                    js: [
                        'https://unpkg.com/[email protected]/dist/vue.global.prod.js',//3.0.0版本有问题
                    ]
                }
            }
            return args;
        });
    },
    configureWebpack: config => {
        const plugins = [];
        if (isProd) {
            // externals里的模块不打包
            const externals = {
                'vue': 'Vue',
            }
            config.externals = externals;
        }
        return { plugins }
    }
}