Vue: Two or three questions about quoting jquery

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.