此文章介紹vue-cli腳手架config目錄下index.js配置文件
1、此配置文件是用來定義開發環境和生產環境中所需要的參數
2、關于注釋
當涉及到較復雜的解釋我將通過標識的方式(如(1))將解釋寫到單獨的注釋模塊,請自行查看
3、上代碼
// see http://vuejs-templates.github.io/webpack for documentation.// path是node.js的路徑模塊,用來處理路徑統一的問題var path = require('path')module.exports = { // 下面是build也就是生產編譯環境下的一些配置 build: { // 導入prod.env.js配置文件,只要用來指定當前環境,詳細見(1) env: require('./prod.env'), // 下面是相對路徑的拼接,假如當前跟目錄是config,那么下面配置的index屬性的屬性值就是dist/index.html index: path.resolve(__dirname, '../dist/index.html'), // 下面定義的是靜態資源的根目錄 也就是dist目錄 assetsRoot: path.resolve(__dirname, '../dist'), // 下面定義的是靜態資源根目錄的子目錄static,也就是dist目錄下面的static assetsSubDirectory: 'static', // 下面定義的是靜態資源的公開路徑,也就是真正的引用路徑 assetsPublicPath: '/', // 下面定義是否生成生產環境的sourcmap,sourcmap是用來debug編譯后文件的,通過映射到編譯前文件來實現 productionSourceMap: true, // Gzip off by default as many popular static hosts such as // Surge or Netlify already gzip all static assets for you. // Before setting to `true`, make sure to: // npm install --save-dev compression-webpack-plugin // 下面是是否在生產環境中壓縮代碼,如果要壓縮必須安裝compression-webpack-plugin productionGzip: false, // 下面定義要壓縮哪些類型的文件 productionGzipExtensions: ['js', 'css'], // Run the build command with an extra argument to // View the bundle analyzer report after build finishes: // `npm run build --report` // Set to `true` or `false` to always turn it on or off // 下面是用來開啟編譯完成后的報告,可以通過設置值為true和false來開啟或關閉 // 下面的process.env.npm_config_report表示定義的一個npm_config_report環境變量,可以自行設置 bundleAnalyzerReport: process.env.npm_config_report }, dev: { // 引入當前目錄下的dev.env.js,用來指明開發環境,詳見(2) env: require('./dev.env'), // 下面是dev-server的端口號,可以自行更改 port: 8080, // 下面表示是否自定代開瀏覽器 autoOpenBrowser: true, assetsSubDirectory: 'static', assetsPublicPath: '/', // 下面是代理表,作用是用來,建一個虛擬api服務器用來代理本機的請求,只能用于開發模式 // 詳見(3) proxyTable: {}, // CSS Sourcemaps off by default because relative paths are "buggy" // with this option, according to the CSS-Loader README // (https://github.com/webpack/css-loader#sourcemaps) // In our experience, they generally work as expected, // just be aware of this issue when enabling this option. // 是否生成css,map文件,上面這段英文就是說使用這個cssmap可能存在問題,但是按照經驗,問題不大,可以使用 // 給人覺得沒必要用這個,css出了問題,直接控制臺不就完事了 cssSourceMap: false }}
新聞熱點
疑難解答
圖片精選