调整了很多次终于见到效果 , 发现最根本的问题在于 被external的包是否依赖Vue, 如果依赖就要把Vue先加external
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| vue.config.js
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
module.exports = { publicPath: '/saas-manager',
configureWebpack: { externals: { vue: 'Vue', 'element-ui': 'ELEMENT', }, }, chainWebpack: (config) => { config.output.filename('js/[name].[hash:6].js') .chunkFilename('js/[name].[hash:6].js') .end();
config .plugin('webpack-bundle-analyzer') .use(BundleAnalyzerPlugin) .init((Plugin) => new Plugin());
|
js文件未做任何调整
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| main.js
import Vue from 'vue'; import ElementUI from 'element-ui'; import axios from 'axios'; import VueAxios from 'vue-axios'; import elementUtils from 'vue-element-utils';
import App from './App.vue'; import router from './router'; import store from './store';
Vue.config.productionTip = false;
Vue.use(ElementUI, { size: 'small', zIndex: 3000, });
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| index.html <head> // 外部css <link href="https://cdn.bootcdn.net/ajax/libs/element-ui/2.14.1/theme-chalk/index.css" rel="stylesheet"> <link rel="stylesheet" href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.4.1/css/bootstrap.css"> </head> <body> // 外部js <script src="https://cdn.bootcdn.net/ajax/libs/vue/2.6.11/vue.js"></script> <script src="https://cdn.bootcdn.net/ajax/libs/element-ui/2.14.1/index.js"></script> ...
<div id="app"></div> </body>
|