module.exports = { publicPath:"/", outputDir: 'dist', // 構建輸出目錄 assetsDir: 'assets', // 靜態資源目錄 (js, css, img, fonts) chainWebpack: config => { //打包配置時間戳 if (process.env.NODE_ENV === 'production') { // 給js和css配置版本號 config.output.filename('js/[name].' + Timestamp + '.js').end(); config.output.chunkFilename('js/[name].' + Timestamp + '.js').end(); config.plugin('extract-css').tap(() => [{ filename: `css/[name].${Timestamp}.css`, chunkFilename: `css/[name].${Timestamp}.css` }]) } }, lintOnSave: false, // 是否開啟eslint保存檢測,有效值:ture | false | 'error' runtimeCompiler: true, // 運行時版本是否需要編譯 transpileDependencies: [], // 默認babel-loader忽略mode_modules,這里可增加例外的依賴包名 productionSourceMap: false, // 是否在構建生產包時生成 sourceMap 文件,false將提高構建速度 css: { // 配置高於chainWebpack中關於css loader的配置 modules: true, // 是否開啟支持‘foo.module.css’樣式 extract: true, // 是否使用css分離插件 ExtractTextPlugin,采用獨立樣式文件載入,不采用<style>方式內聯至html文件中 sourceMap: false, // 是否在構建樣式地圖,false將提高構建速度 loaderOptions: { // css預設器配置項 sass: { data: ''//`@import "@/assets/scss/mixin.scss";` } } }, parallel: require('os').cpus().length > 1, // 構建時開啟多進程處理babel編譯 pluginOptions: { // 第三方插件配置 }, pwa: { // 單頁插件相關配置 https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-pwa }, devServer: { open: true, host: 'localhost', port: 8080, https: false, hotOnly: false, proxy: { //配置跨域 '/api': { target: 'http://zb.txdou.com', //test ws: true,// 是否啟用websockets changeOrigin: true, //是否開啟代理 pathRewrite: { '^/api': '' } } }, before: app => {} } }
URL添加版本號
router.beforeEach((to, from, next) => { if (to.meta.title) { document.title = to.meta.title } /** * 添加版本號 **/ if (document.URL.indexOf('?t=') < 0) { let timestamp = (new Date()).valueOf() window.location.href = '?t=' + timestamp + '#' + to.fullPath } if (to.meta.requireAuth) { if (getStore('personal') && getStore("loginFlag") == 1) { next(); } else { next({ path: '/login', query: {redirect: to.fullPath} }) } } else { next(); } });