Current location - Health Preservation Learning Network - Slimming men and women - Optimization of Vue project
Optimization of Vue project
babel.config.js

According to the if condition, the plug-in will only take effect in the production stage.

Through command line mode

By visualizing the UI panel

Run vue ui-& gt;; Task->; Construction completed-> analyse

By default, the development mode and release mode of the Vue project * * * use the same package entry file, that is, src/main.js In order to separate the development process and release process of the project, you can specify two package entries.

The development mode is src/main-dev.js.

The publishing mode is src/main-prod.js.

The two ways to modify the configuration of webpack are configureWebpack and chainWebpack, which have the same function, but they are used in different ways.

Vue. configuration.js

By default, the third-party dependencies imported by import will be packaged in the same file, which will cause the file to be too large and affect the loading speed. By configuring the externals node, the third-party dependencies that need to be imported globally are excluded from the packaging file, which can effectively reduce the packaging volume.

The declaration method depends on the package name: registration name. The registered name must be consistent with the name of the object mounted on the window after the introduction of CDN resources. You can use the console.log (window) to print the name of the object. If the object specified by the registered name cannot be found on the window, a blank screen will appear. In addition, if the object name of the imported CDN resource mounted on the window is similar to xx-xx-xx (which does not conform to the js object naming specification), the resource can only be imported through CDN.

Vue. configuration.js

Config.plugin('html') uses HTML plug-ins to pass parameters to the template.

Rigid cast iron

Jet research …

If isProd is true, CDN resources will be imported.

The corresponding resource file will be loaded only when the route is accessed. It is suggested not to package each route separately, but to specify the same package file for multiple routes through webpackChunkName, which can reduce the number of requests.

Router /index.js

Complete configuration

Vue. configuration.js

Main product. js

After the introduction of CDN, the sentences with imported style will be commented or deleted, and only the sentences with imported JS will be kept.