please teach me,
import babelpolyfill from 'babel-polyfill'
import Vue from 'vue'
import App from './App'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-default/index.css'
//import './assets/theme/theme-green/index.css'
import VueRouter from 'vue-router'
import store from './vuex/store'
import Vuex from 'vuex'
//import NProgress from 'nprogress'
//import 'nprogress/nprogress.css'
import routes from './routes'
//import Mock from './mock'
//Mock.bootstrap();
import 'font-awesome/css/font-awesome.min.css'
How to use cdn to reference such public js files. Currently, it is installed by npm install, all are local, and exports are limited. Many packages can be imported using cdn. But currently they are all operated by the Vue framework, and there is no writing place directly imported from HTML. Please tell me how to use a public CDN like https://cdn.bootcss.com/eleme... in the project.
Webpack is configured like this, html introduces cdn’s jquery
Just import it directly from
CDN
inhtml
, there is no need to import it and package/compress it togetherIf the third-party library has a CDN address, it can be directly introduced into the HTML, in the HTML of the template.
Then you can also throw the code to your own cdn, manage it uniformly, and process it in the same way as your other static files. For example, your img files are placed in cdnUrl+projectName/img/, and these third-party libraries are also thrown on it. .
You are currently managed by npm package locally, so if you import it when you quote it, it will definitely be packaged by webpack... This involves the issue of webpack. Let’s see if we can solve the current problem first
You can take a look at the webpack documentation. It is written in the documentation, which is quite detailed. Take jQuery as an example
https://doc.webpack-china.org...
Solving your problem requires the following steps
1. Extract the js files installed locally by npm and introduced through import. This part can be extracted through the CommonsChunkPlugin plug-in. Refer to webpack code separation
For example:
2. Use HtmlWebpackPlugin to solve the problem of path and file name after js packaging
The final generated effect is like this
Your problem mainly lies in the extraction of the above public js files. After extraction, it is a personal choice whether to use HtmlWebpackPlugin to automatically add resource paths or to add them manually, so the focus is on the first step