亚洲精品久久久中文字幕-亚洲精品久久片久久-亚洲精品久久青草-亚洲精品久久婷婷爱久久婷婷-亚洲精品久久午夜香蕉

您的位置:首頁技術文章
文章詳情頁

Vue CLI4 Vue.config.js標準配置(最全注釋)

瀏覽:21日期:2023-01-15 10:28:36

前言:

Vue.js CLI工具 不知不覺發展到了4.0時代,CLI給人最直白的感受是沒有了build文件夾跟config文件夾,所有的配置都在Vue.config.js完成。那么該文件的配置至關重要。現在我們來看一下最新配置是怎么配置的。

安裝

npm i -d vue-cli-configjs

// vue.config.jsconst path = require(’path’);const CompressionWebpackPlugin = require('compression-webpack-plugin'); // 開啟gzip壓縮, 按需引用const productionGzipExtensions = /.(js|css|json|txt|html|ico|svg)(?.*)?$/i; // 開啟gzip壓縮, 按需寫入const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin; // 打包分析const IS_PROD = [’production’, ’prod’].includes(process.env.NODE_ENV);const resolve = (dir) => path.join(__dirname, dir);module.exports = { publicPath: process.env.NODE_ENV === ’production’ ? ’/site/vue-demo/’ : ’/’, // 公共路徑 indexPath: ’index.html’ , // 相對于打包路徑index.html的路徑 outputDir: process.env.outputDir || ’dist’, // ’dist’, 生產環境構建文件的目錄 assetsDir: ’static’, // 相對于outputDir的靜態資源(js、css、img、fonts)目錄 lintOnSave: false, // 是否在開發環境下通過 eslint-loader 在每次保存時 lint 代碼 runtimeCompiler: true, // 是否使用包含運行時編譯器的 Vue 構建版本 productionSourceMap: !IS_PROD, // 生產環境的 source map parallel: require('os').cpus().length > 1, // 是否為 Babel 或 TypeScript 使用 thread-loader。該選項在系統的 CPU 有多于一個內核時自動啟用,僅作用于生產構建。 pwa: {}, // 向 PWA 插件傳遞選項。 chainWebpack: config => { config.resolve.symlinks(true); // 修復熱更新失效 // 如果使用多頁面打包,使用vue inspect --plugins查看html是否在結果數組中 config.plugin('html').tap(args => { // 修復 Lazy loading routes Error args[0].chunksSortMode = 'none'; return args; }); config.resolve.alias // 添加別名 .set(’@’, resolve(’src’)) .set(’@assets’, resolve(’src/assets’)) .set(’@components’, resolve(’src/components’)) .set(’@views’, resolve(’src/views’)) .set(’@store’, resolve(’src/store’)); // 壓縮圖片 // 需要 npm i -D image-webpack-loader config.module .rule('images') .use('image-webpack-loader') .loader('image-webpack-loader') .options({mozjpeg: { progressive: true, quality: 65 },optipng: { enabled: false },pngquant: { quality: [0.65, 0.9], speed: 4 },gifsicle: { interlaced: false },webp: { quality: 75 } }); // 打包分析, 打包之后自動生成一個名叫report.html文件(可忽視) if (IS_PROD) { config.plugin('webpack-report').use(BundleAnalyzerPlugin, [{ analyzerMode: 'static'} ]); } }, configureWebpack: config => { // 開啟 gzip 壓縮 // 需要 npm i -D compression-webpack-plugin const plugins = []; if (IS_PROD) { plugins.push(new CompressionWebpackPlugin({ filename: '[path].gz[query]', algorithm: 'gzip', test: productionGzipExtensions, threshold: 10240, minRatio: 0.8}) ); } config.plugins = [...config.plugins, ...plugins]; }, css: { extract: IS_PROD, requireModuleExtension: false,// 去掉文件名中的 .module loaderOptions: {// 給 less-loader 傳遞 Less.js 相關選項less: { // `globalVars` 定義全局對象,可加入全局變量 globalVars: { primary: ’#333’ }} } }, devServer: { overlay: { // 讓瀏覽器 overlay 同時顯示警告和錯誤 warnings: true, errors: true }, host: 'localhost', port: 8080, // 端口號 https: false, // https:{type:Boolean} open: false, //配置自動啟動瀏覽器 hotOnly: true, // 熱更新 // proxy: ’http://localhost:8080’ // 配置跨域處理,只有一個代理 proxy: { //配置多個跨域'/api': { target: 'http://172.11.11.11:7071', changeOrigin: true, // ws: true,//websocket支持 secure: false, pathRewrite: { '^/api': '/' }},'/api2': { target: 'http://172.12.12.12:2018', changeOrigin: true, //ws: true,//websocket支持 secure: false, pathRewrite: { '^/api2': '/' }}, } }}

結語

上述代碼可以直接復制,也可以按需引入,一般都用的到,注意里面需要安裝的依賴。

cnpm install --save-dev compression-webpack-plugin

cnpm install --save-dev image-webpack-loader

到此這篇關于Vue CLI4 Vue.config.js標準配置(最全注釋)的文章就介紹到這了,更多相關Vue.config.js標準配置內容請搜索好吧啦網以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持好吧啦網!,希望大家以后多多支持好吧啦網!

標簽: Vue
相關文章:
主站蜘蛛池模板: 性生大片一级毛片免费观看 | 大学生一级一片第一次欧美 | 久久精品嫩草影院免费看 | 黄色一级视频欧美 | 亚洲专区视频 | 日韩99在线| 国产最新在线视频 | 1024视频在线观看国产成人 | 色片免费观看 | 亚洲最大在线视频 | 欧美在线黄 | 精品成人免费播放国产片 | 国产主播久久 | 欧美日韩中文一区二区三区 | 国产a久久精品一区二区三区 | 婷婷久久久五月综合色 | 久久影院中文字幕 | 亚洲性综合网 | 香蕉啪 | 国模人体肉肉拍拍 | 亚洲黄色片在线观看 | 国产caoni111在线观看视频 | 大片免费观看在线视频 | 欧美一级一一特黄 | 哪有黄色网址 | 久久综合色综合 | 国产aⅴ一区二区 | 日韩免费毛片全部不收费 | 中文字幕成人网 | 欧美a在线视频 | 91精品国产综合久久精品 | 欧美午夜a级精美理论片 | 久久久久久久国产视频 | 在线观看国产免费高清不卡 | 丁香六月色婷婷 | 免费在线观看黄色小视频 | 香蕉高清免费永久在线视频 | 青草青草伊人精品视频 | 日韩免费高清一级毛片在线 | 欧洲美女粗暴交视频 | 亚洲综合网在线观看首页 |