Webpack version: 3.6.0
The first is to refer to jquery.
There are two places to change.
1 (Project address)/build/webpack.base.conf.js
2 (Project address)/src/main.js
Webpack.base.conf.js:
(1) Introduce the Webpack variable under ' use strict '.
Const WEBPACK = require (' Webpack ')
(2) Module.exports object:
(There is no modification, no on Add.) )
Resolve object:
Resolve: { extensions: ['. js ', '. Vue ', '. JSON '], alias: { ' vue$ ': ' Vue/dist/vue.esm.js ' @ ': Resolve (' src ') ,' jquery ': ' jquery ' } },
Plugins object:
plugins: [ new webpack. Provideplugin ({ "jquery", "jquery" }) ],
Main.js:
Import $ from ' jquery '
Just put it together with the other import.
We can verify whether the introduction was successful.
Find a Vue file:
mounted () { $ (' body '). css ({ ' background-color ': ' #efefef ' }) },
You can see that the background color of the page is really broken.
Let's see what happens to the size of the package before and after the reference.
You can find that the Vendor.js file becomes 87kb larger.
If only jquery may be okay, but if you also introduce something else (such as a variety of UI component libraries), then your project may be bloated, and your boss might say: How does your project turn out so slowly?
Of course, there is the external introduction of the required library JS file, and then in the Webpack settings do not package the library.
Set jquery as a non-packaged library.
Index.html:
(Project address)/index.html
<src= "Https://code.jquery.com/jquery-3.2.1.min.js"></ Script>
Webpack.base.conf.js:
Module.exports object:
Externals object:
externals: { ' jquery ': ' $ ' },
Let's take a look at the modified effect.
It can be found that the volume of the Vendor.js has changed back to 112KB.
In addition, I took a look at the comment question.
After I commented out a piece of code, I found that the packaged app.js file became smaller.
In other words, comments written in the Vue file are not packaged.
Reference:
1190000007020623
Vue: Two or three questions about quoting jquery