const path = require('path') const UglifyPlugin = require('uglifyjs-webpack-plugin') module.exports = { publicPath: './', // 基本路徑 outputDir: 'dist', // 輸出文件目錄 lintOnSave: false, // eslint-loader 是否在保存的時候檢查 // see https://github.com/vuejs/vue-cli/blob/dev/docs/webpack.md // webpack配置 chainWebpack: (config) => { }, configureWebpack: (config) => { if (process.env.NODE_ENV === 'production') { // 爲生產環境修改配置... config.mode = 'production' // 將每一個依賴包打包成單獨的js文件 let optimization = { runtimeChunk: 'single', splitChunks: { chunks: 'all', maxInitialRequests: Infinity, minSize: 20000, cacheGroups: { vendor: { test: /[\\/]node_modules[\\/]/, name (module) { // get the name. E.g. node_modules/packageName/not/this/part.js // or node_modules/packageName const packageName = module.context.match(/[\\/]node_modules[\\/](.*?)([\\/]|$)/)[1] // npm package names are URL-safe, but some servers don't like @ symbols return `npm.${packageName.replace('@', '')}` } } } }, minimizer: [new UglifyPlugin({ uglifyOptions: { compress: { warnings: false, drop_console: true, // console drop_debugger: false, pure_funcs: ['console.log'] // 移除console } } })] } Object.assign(config, { optimization }) } else { // 爲開發環境修改配置... config.mode = 'development' } Object.assign(config, { // 開發生產共同配置 resolve: { alias: { '@': path.resolve(__dirname, './src'), '@c': path.resolve(__dirname, './src/components'), '@p': path.resolve(__dirname, './src/pages') } // 別名配置 } }) }, productionSourceMap: false, // 生產環境是否生成 sourceMap 文件 // css相關配置 css: { extract: true, // 是否使用css分離插件 ExtractTextPlugin sourceMap: false, // 開啓 CSS source maps? loaderOptions: { css: {}, // 這裏的選項會傳遞給 css-loader postcss: {} // 這裏的選項會傳遞給 postcss-loader }, // css預設器配置項 modules: false // 啓用 CSS modules for all css / pre-processor files. }, parallel: require('os').cpus().length > 1, // 是否爲 Babel 或 TypeScript 使用 thread-loader。該選項在系統的 CPU 有多於一個內核時自動啓用,僅做用於生產構建。 pwa: {}, // PWA 插件相關配置 see https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-pwa // webpack-dev-server 相關配置 devServer: { open: process.platform === 'darwin', host: '0.0.0.0', // 容許外部ip訪問 port: 2333, // 端口 https: false, // 啓用https overlay: { warnings: true, errors: true }, // 錯誤、警告在頁面彈出 proxy: { '/api': { target: 'http://www.baidu.com/api', changeOrigin: true, // 容許websockets跨域 // ws: true, pathRewrite: { '^/api': '' } } } // 代理轉發配置,用於調試環境 }, // 第三方插件配置 pluginOptions: {} }
module.exports = { baseUrl: process.env.NODE_ENV === 'production' ? '//your_url' : '/', outputDir: 'dist', assetsDir: 'static', filenameHashing: true, // When building in multi-pages mode, the webpack config will contain different plugins // (there will be multiple instances of html-webpack-plugin and preload-webpack-plugin). // Make sure to run vue inspect if you are trying to modify the options for those plugins. pages: { index: { // entry for the pages entry: 'src/pages/index/index.js', // the source template template: 'src/pages/index/index.html', // output as dist/index.html filename: 'index.html', // when using title option, // template title tag needs to be <title><%= htmlWebpackPlugin.options.title %></title> title: '首頁', // chunks to include on this pages, by default includes // extracted common chunks and vendor chunks. chunks: ['chunk-vendors', 'chunk-common', 'index'] } // when using the entry-only string format, // template is inferred to be `public/subpage.html` // and falls back to `public/index.html` if not found. // Output filename is inferred to be `subpage.html`. // subpage: '' }, // eslint-loader 是否在保存的時候檢查 lintOnSave: true, // 是否使用包含運行時編譯器的Vue核心的構建 runtimeCompiler: false, // 默認狀況下 babel-loader 忽略其中的全部文件 node_modules transpileDependencies: [], // 生產環境 sourceMap productionSourceMap: false, // cors 相關 https://jakearchibald.com/2017/es-modules-in-browsers/#always-cors // corsUseCredentials: false, // webpack 配置,鍵值對象時會合並配置,爲方法時會改寫配置 // https://cli.vuejs.org/guide/webpack.html#simple-configuration configureWebpack: (config) => { }, // webpack 連接 API,用於生成和修改 webapck 配置 // https://github.com/mozilla-neutrino/webpack-chain chainWebpack: (config) => { // 由於是多頁面,因此取消 chunks,每一個頁面只對應一個單獨的 JS / CSS config.optimization .splitChunks({ cacheGroups: {} }); // 'src/lib' 目錄下爲外部庫文件,不參與 eslint 檢測 config.module .rule('eslint') .exclude .add('/Users/maybexia/Downloads/FE/community_built-in/src/lib') .end() }, // 配置高於chainWebpack中關於 css loader 的配置 css: { // 是否開啓支持 foo.module.css 樣式 modules: false, // 是否使用 css 分離插件 ExtractTextPlugin,採用獨立樣式文件載入,不採用 <style> 方式內聯至 html 文件中 extract: true, // 是否構建樣式地圖,false 將提升構建速度 sourceMap: false, // css預設器配置項 loaderOptions: { css: { // options here will be passed to css-loader }, postcss: { // options here will be passed to postcss-loader } } }, // All options for webpack-dev-server are supported // https://webpack.js.org/configuration/dev-server/ devServer: { open: true, host: '127.0.0.1', port: 3000, https: false, hotOnly: false, proxy: null, before: app => { } }, // 構建時開啓多進程處理 babel 編譯 parallel: require('os').cpus().length > 1, // https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-pwa pwa: {}, // 第三方插件配置 pluginOptions: {} };
module.exports = { // 部署應用時的基本 URL baseUrl: process.env.NODE_ENV === 'production' ? '192.168.60.110:8080' : '192.168.60.110:8080', // build時構建文件的目錄 構建時傳入 --no-clean 可關閉該行爲 outputDir: 'dist', // build時放置生成的靜態資源 (js、css、img、fonts) 的 (相對於 outputDir 的) 目錄 assetsDir: '', // 指定生成的 index.html 的輸出路徑 (相對於 outputDir)。也能夠是一個絕對路徑。 indexPath: 'index.html', // 默認在生成的靜態資源文件名中包含hash以控制緩存 filenameHashing: true, // 構建多頁面應用,頁面的配置 pages: { index: { // page 的入口 entry: 'src/index/main.js', // 模板來源 template: 'public/index.html', // 在 dist/index.html 的輸出 filename: 'index.html', // 當使用 title 選項時,template 中的 title 標籤須要是 <title><%= htmlWebpackPlugin.options.title %></title> title: 'Index Page', // 在這個頁面中包含的塊,默認狀況下會包含 // 提取出來的通用 chunk 和 vendor chunk。 chunks: ['chunk-vendors', 'chunk-common', 'index'] }, // 當使用只有入口的字符串格式時,模板會被推導爲 `public/subpage.html`,而且若是找不到的話,就回退到 `public/index.html`。 // 輸出文件名會被推導爲 `subpage.html`。 subpage: 'src/subpage/main.js' }, // 是否在開發環境下經過 eslint-loader 在每次保存時 lint 代碼 (在生產構建時禁用 eslint-loader) lintOnSave: process.env.NODE_ENV !== 'production', // 是否使用包含運行時編譯器的 Vue 構建版本 runtimeCompiler: false, // Babel 顯式轉譯列表 transpileDependencies: [], // 若是你不須要生產環境的 source map,能夠將其設置爲 false 以加速生產環境構建 productionSourceMap: true, // 設置生成的 HTML 中 <link rel="stylesheet"> 和 <script> 標籤的 crossorigin 屬性(注:僅影響構建時注入的標籤) crossorigin: '', // 在生成的 HTML 中的 <link rel="stylesheet"> 和 <script> 標籤上啓用 Subresource Integrity (SRI) integrity: false, // 若是這個值是一個對象,則會經過 webpack-merge 合併到最終的配置中 // 若是你須要基於環境有條件地配置行爲,或者想要直接修改配置,那就換成一個函數 (該函數會在環境變量被設置以後懶執行)。該方法的第一個參數會收到已經解析好的配置。在函數內,你能夠直接修改配置,或者返回一個將會被合併的對象 configureWebpack: {}, // 對內部的 webpack 配置(好比修改、增長Loader選項)(鏈式操做) chainWebpack: () => { }, // css的處理 css: { // 當爲true時,css文件名可省略 module 默認爲 false modules: true, // 是否將組件中的 CSS 提取至一個獨立的 CSS 文件中,看成爲一個庫構建時,你也能夠將其設置爲 false 省得用戶本身導入 CSS // 默認生產環境下是 true,開發環境下是 false extract: false, // 是否爲 CSS 開啓 source map。設置爲 true 以後可能會影響構建的性能 sourceMap: false, //向 CSS 相關的 loader 傳遞選項(支持 css-loader postcss-loader sass-loader less-loader stylus-loader) loaderOptions: { css: {}, less: {} } }, // 全部 webpack-dev-server 的選項都支持 devServer: {}, // 是否爲 Babel 或 TypeScript 使用 thread-loader parallel: require('os').cpus().length > 1, // 向 PWA 插件傳遞選項 pwa: {}, // 能夠用來傳遞任何第三方插件選項 pluginOptions: {} }