backgroundThere is a local configuration file in the project: // src/image-position.js export default { label: 'Homepage', value: 'home', data: [ { label: 'Carousel', value: 'carousel' } ] } Everyone knows how to reference a local file: import ImagePosition from './image-position.js' Now you need to drop the image-position.js file onto the server and get its link: xxx.com/static/imag… At this time, it is naturally not feasible for you to directly quote the file address. import ImagePosition from 'https://xxx.com/static/image-position.js' // ERROR This dependency was not found accomplishFirst, make a small modification to image-position.js to expose a global object ImagePosition // Modified image-position.js (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : typeof define === 'function' && define.amd ? define(factory) : (global = global || self, global.ImagePosition = factory()); }(this, (function () { 'use strict'; return { label: 'Homepage', value: 'home', data: [ { label: 'Carousel', value: 'carousel' } ] }; }))); Add externals in vue.config.js file. module.exports = { configureWebpack: config => { config.externals = { 'image-position': 'ImagePosition' } } } index.html distinguishes the environment and imports js files. // public/index.html <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> <meta name="renderer" content="webkit"> <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"> <title><%= htmlWebpackPlugin.options.title %></title> </head> <body> <div id="app"></div> <!-- built files will be auto injected --> <% if (NODE_ENV == 'production') { %> <script src="http://xxx.com/static/image-position.js"></script> <% } else { %> <script src="http://test.xxx.com/static/image-position.js"></script> <% } %> </body> </html> After completing the above steps, you can happily reference the image-position.js file. import ImagePosition from 'image-position' console.log(ImagePosition) // {label: 'Home', value: 'home', data: [{label: 'Carousel', value: 'carousel'}]} Supplement how to configure under vue-cli2.0// build/webpack.base.conf.js module.exports = { externals: { // Add 'image-position': 'ImagePosition' } } // index.html <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> <meta name="renderer" content="webkit"> <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"> <title><%= htmlWebpackPlugin.options.title %></title> </head> <body> <div id="app"></div> <!-- built files will be auto injected --> <% if (process.env == 'production') { %> <script src="http://xxx.com/static/image-position.js"></script> <% } else { %> <script src="http://test.xxx.com/static/image-position.js"></script> <% } %> </body> </html> SummarizeIn the packaging volume optimization of Vue projects, CDN acceleration is a commonly used method. The above is actually the implementation content of CDN acceleration. The third-party library is introduced through the script tag, which greatly reduces the size of the packaged vendor.js file. When we want to remotely place local files on a server, the key lies in the first step of the implementation process. The rest of the content is the same as the process of configuring CDN acceleration. The above is the details of how Vue imports the js configuration file on the server. For more information about Vue import js configuration file, please pay attention to other related articles on 123WORDPRESS.COM! You may also be interested in:
|
<<: View the number of files in each subfolder of a specified folder in Linux
>>: mysql5.7.19 winx64 decompressed version installation and configuration tutorial
Table of contents introduction 1. What is one-cli...
Web Server 1. The web server turns off unnecessar...
Table of contents 1. The origin of tomcat 1. Tomc...
The rewrite module is the ngx_http_rewrite_module...
When writing my own demo, I want to use display:f...
In the latest version of Ubuntu, users no longer ...
Table of contents Install Tomcat Download Tomcat ...
Table of contents What is Docker deploy 1. Pull t...
This article shares the specific process of js ob...
Preface ORDER BY 字段名升序/降序, I believe that everyon...
1. Add Maria source vi /etc/yum.repos.d/MariaDB.r...
Table of contents 1. In project development, the ...
cause The reason for writing this blog is that I ...
Preface This article mainly introduces the releva...
The use of vue3 Teleport instant movement functio...