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

cdn vue3 提示 Vue is not undefined #55

Open
carcar96 opened this issue Apr 16, 2021 · 3 comments
Open

cdn vue3 提示 Vue is not undefined #55

carcar96 opened this issue Apr 16, 2021 · 3 comments

Comments

@carcar96
Copy link

// cdn预加载使用
const externals = {
'vue': 'Vue', // 与这个'Vue'的写法有关吗?Vue3不暴露Vue了,而是createApp
}

@carcar96
Copy link
Author

carcar96 commented Apr 18, 2021

打包时,注释掉:// import { createApp } from 'vue';
const app = createApp(); 改成 const app = Vue.createApp(App); 即可

@awesomepeng
Copy link

打包时,注释掉:// import { createApp } from 'vue';
const = app = createApp(); 改成 const app = Vue.createApp(App); 即可

可以写一下你的代码么

@carcar96
Copy link
Author

打包时,注释掉:// 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/vue@3.0.11/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 }
    }
}

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

2 participants