From 0d3b87cd48fff189f4ace13a68019e0a2711db1e Mon Sep 17 00:00:00 2001 From: vvchen Date: Thu, 25 May 2017 09:35:19 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E9=85=8D=E7=BD=AE=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build/dev-server.js | 6 ++++-- build/vendor-manifest.json | 2 +- build/webpack.dev.conf.js | 14 +++++++++++++- build/webpack.dll.conf.js | 2 +- build/webpack.prod.conf.js | 13 ++++++++++++- config/index.js | 2 +- config/site.config.js | 2 +- index.html | 3 ++- src/service/api.js | 22 +++++++++++----------- 9 files changed, 46 insertions(+), 20 deletions(-) diff --git a/build/dev-server.js b/build/dev-server.js index 47925c7..ff21930 100644 --- a/build/dev-server.js +++ b/build/dev-server.js @@ -29,7 +29,7 @@ var devMiddleware = require('webpack-dev-middleware')(compiler, { }) var hotMiddleware = require('webpack-hot-middleware')(compiler, { - log: () => {} + log: () => { } }) // force page reload when html-webpack-plugin template changes compiler.plugin('compilation', function (compilation) { @@ -53,7 +53,9 @@ Object.keys(proxyTable).forEach(function (context) { }) // handle fallback for HTML5 history API -app.use(require('connect-history-api-fallback')()) +app.use(require('connect-history-api-fallback')({ + index: '/index.html' +})) // serve webpack bundle output app.use(devMiddleware) diff --git a/build/vendor-manifest.json b/build/vendor-manifest.json index 18f0b9a..d4aca07 100644 --- a/build/vendor-manifest.json +++ b/build/vendor-manifest.json @@ -1 +1 @@ -{"name":"vendor_ba6bb1a87c3b81f444e6","content":{"./node_modules/axios/lib/utils.js":{"id":0,"meta":{}},"./node_modules/process/browser.js":{"id":1,"meta":{}},"./node_modules/axios/lib/defaults.js":{"id":2,"meta":{}},"./node_modules/webpack/buildin/global.js":{"id":3,"meta":{}},"./node_modules/axios/lib/adapters/xhr.js":{"id":4,"meta":{}},"./node_modules/axios/lib/cancel/Cancel.js":{"id":5,"meta":{}},"./node_modules/axios/lib/cancel/isCancel.js":{"id":6,"meta":{}},"./node_modules/axios/lib/core/createError.js":{"id":7,"meta":{}},"./node_modules/axios/lib/helpers/bind.js":{"id":8,"meta":{}},"./node_modules/axios/index.js":{"id":9,"meta":{}},"./node_modules/element-ui/lib/index.js":{"id":10,"meta":{}},"./node_modules/vue-router/dist/vue-router.esm.js":{"id":11,"meta":{"harmonyModule":true},"exports":["default"]},"./node_modules/vue/dist/vue.common.js":{"id":12,"meta":{}},"./node_modules/vuex/dist/vuex.esm.js":{"id":13,"meta":{"harmonyModule":true},"exports":["Store","mapState","mapMutations","mapGetters","mapActions","default"]},"./node_modules/axios/lib/axios.js":{"id":14,"meta":{}},"./node_modules/axios/lib/cancel/CancelToken.js":{"id":15,"meta":{}},"./node_modules/axios/lib/core/Axios.js":{"id":16,"meta":{}},"./node_modules/axios/lib/core/InterceptorManager.js":{"id":17,"meta":{}},"./node_modules/axios/lib/core/dispatchRequest.js":{"id":18,"meta":{}},"./node_modules/axios/lib/core/enhanceError.js":{"id":19,"meta":{}},"./node_modules/axios/lib/core/settle.js":{"id":20,"meta":{}},"./node_modules/axios/lib/core/transformData.js":{"id":21,"meta":{}},"./node_modules/axios/lib/helpers/btoa.js":{"id":22,"meta":{}},"./node_modules/axios/lib/helpers/buildURL.js":{"id":23,"meta":{}},"./node_modules/axios/lib/helpers/combineURLs.js":{"id":24,"meta":{}},"./node_modules/axios/lib/helpers/cookies.js":{"id":25,"meta":{}},"./node_modules/axios/lib/helpers/isAbsoluteURL.js":{"id":26,"meta":{}},"./node_modules/axios/lib/helpers/isURLSameOrigin.js":{"id":27,"meta":{}},"./node_modules/axios/lib/helpers/normalizeHeaderName.js":{"id":28,"meta":{}},"./node_modules/axios/lib/helpers/parseHeaders.js":{"id":29,"meta":{}},"./node_modules/axios/lib/helpers/spread.js":{"id":30,"meta":{}},"./node_modules/base64-js/index.js":{"id":31,"meta":{}},"./node_modules/buffer/index.js":{"id":32,"meta":{}},"./node_modules/ieee754/index.js":{"id":33,"meta":{}},"./node_modules/isarray/index.js":{"id":34,"meta":{}},"./node_modules/vue/dist/vue.runtime.esm.js":{"id":35,"meta":{"harmonyModule":true},"exports":["default"]}}} \ No newline at end of file +{"name":"vendor_52d3196af34d31c412d3","content":{"./node_modules/axios/lib/utils.js":{"id":0,"meta":{}},"./node_modules/process/browser.js":{"id":1,"meta":{}},"./node_modules/axios/lib/defaults.js":{"id":2,"meta":{}},"./node_modules/webpack/buildin/global.js":{"id":3,"meta":{}},"./node_modules/axios/lib/adapters/xhr.js":{"id":4,"meta":{}},"./node_modules/axios/lib/cancel/Cancel.js":{"id":5,"meta":{}},"./node_modules/axios/lib/cancel/isCancel.js":{"id":6,"meta":{}},"./node_modules/axios/lib/core/createError.js":{"id":7,"meta":{}},"./node_modules/axios/lib/helpers/bind.js":{"id":8,"meta":{}},"./node_modules/axios/index.js":{"id":9,"meta":{}},"./node_modules/element-ui/lib/index.js":{"id":10,"meta":{}},"./node_modules/vue-router/dist/vue-router.esm.js":{"id":11,"meta":{"harmonyModule":true},"exports":["default"]},"./node_modules/vue/dist/vue.common.js":{"id":12,"meta":{}},"./node_modules/vuex/dist/vuex.esm.js":{"id":13,"meta":{"harmonyModule":true},"exports":["Store","mapState","mapMutations","mapGetters","mapActions","default"]},"./node_modules/axios/lib/axios.js":{"id":14,"meta":{}},"./node_modules/axios/lib/cancel/CancelToken.js":{"id":15,"meta":{}},"./node_modules/axios/lib/core/Axios.js":{"id":16,"meta":{}},"./node_modules/axios/lib/core/InterceptorManager.js":{"id":17,"meta":{}},"./node_modules/axios/lib/core/dispatchRequest.js":{"id":18,"meta":{}},"./node_modules/axios/lib/core/enhanceError.js":{"id":19,"meta":{}},"./node_modules/axios/lib/core/settle.js":{"id":20,"meta":{}},"./node_modules/axios/lib/core/transformData.js":{"id":21,"meta":{}},"./node_modules/axios/lib/helpers/btoa.js":{"id":22,"meta":{}},"./node_modules/axios/lib/helpers/buildURL.js":{"id":23,"meta":{}},"./node_modules/axios/lib/helpers/combineURLs.js":{"id":24,"meta":{}},"./node_modules/axios/lib/helpers/cookies.js":{"id":25,"meta":{}},"./node_modules/axios/lib/helpers/isAbsoluteURL.js":{"id":26,"meta":{}},"./node_modules/axios/lib/helpers/isURLSameOrigin.js":{"id":27,"meta":{}},"./node_modules/axios/lib/helpers/normalizeHeaderName.js":{"id":28,"meta":{}},"./node_modules/axios/lib/helpers/parseHeaders.js":{"id":29,"meta":{}},"./node_modules/axios/lib/helpers/spread.js":{"id":30,"meta":{}},"./node_modules/base64-js/index.js":{"id":31,"meta":{}},"./node_modules/buffer/index.js":{"id":32,"meta":{}},"./node_modules/ieee754/index.js":{"id":33,"meta":{}},"./node_modules/isarray/index.js":{"id":34,"meta":{}},"./node_modules/vue/dist/vue.runtime.esm.js":{"id":35,"meta":{"harmonyModule":true},"exports":["default"]}}} \ No newline at end of file diff --git a/build/webpack.dev.conf.js b/build/webpack.dev.conf.js index 530c3a0..33a6679 100644 --- a/build/webpack.dev.conf.js +++ b/build/webpack.dev.conf.js @@ -1,3 +1,4 @@ +var path = require('path') var utils = require('./utils') var webpack = require('webpack') var config = require('../config') @@ -11,6 +12,16 @@ var CopyWebpackPlugin = require('copy-webpack-plugin') Object.keys(baseWebpackConfig.entry).forEach(function (name) { baseWebpackConfig.entry[name] = ['./build/dev-client'].concat(baseWebpackConfig.entry[name]) }) + +// 获取带hash值的dll文件名称 +var glob=require('glob') +var dllJsFilePath, + dllJsFileName +dllJsFilePath=glob.sync(path.join(__dirname, '../src/vendor_*.dll.js'))[0] +if (dllJsFilePath){ + dllJsFileName= path.basename(dllJsFilePath) +} + module.exports = merge(baseWebpackConfig, { module: { rules: utils.styleLoaders({ sourceMap: config.dev.cssSourceMap }) @@ -29,13 +40,14 @@ module.exports = merge(baseWebpackConfig, { filename: 'index.html', favicon: './src/assets/img/favicon.ico', template: 'index.html', + dllJsFileName : dllJsFileName, inject: true }), // 拷贝mock数据文件到构建目录 new CopyWebpackPlugin([ { from: 'src/mock', to: 'mock' }, - { from: 'src/vendor.dll.js', to: 'static/js' } + { from: 'src/vendor_*.dll.js', to: 'static/js/[name].[ext]' } ], { // 忽略选项 ignore: [ diff --git a/build/webpack.dll.conf.js b/build/webpack.dll.conf.js index 889b76e..7ebe1b4 100644 --- a/build/webpack.dll.conf.js +++ b/build/webpack.dll.conf.js @@ -19,7 +19,7 @@ module.exports = { }, output: { path: path.resolve(__dirname, '../src'), - filename: '[name].dll.js', + filename: '[name]_[hash].dll.js', library: '[name]_[hash]' }, module: { diff --git a/build/webpack.prod.conf.js b/build/webpack.prod.conf.js index c0a90e8..3382033 100644 --- a/build/webpack.prod.conf.js +++ b/build/webpack.prod.conf.js @@ -11,6 +11,16 @@ var OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin') var CopyWebpackPlugin = require('copy-webpack-plugin') var env = config.build.env +// 获取带hash值的dll文件名称 +var glob=require('glob') +var dllJsFilePath, + dllJsFileName +dllJsFilePath=glob.sync(path.join(__dirname, '../src/vendor_*.dll.js'))[0] +if (dllJsFilePath){ + // dllJsFileName= dllJsFilePath.split('src/')[1] + dllJsFileName= path.basename(dllJsFilePath) +} + var webpackConfig = merge(baseWebpackConfig, { module: { rules: utils.styleLoaders({ @@ -53,6 +63,7 @@ var webpackConfig = merge(baseWebpackConfig, { filename: config.build.index, favicon: './src/assets/img/favicon.ico', template: 'index.html', + dllJsFileName: dllJsFileName, inject: true, minify: { removeComments: true, @@ -87,7 +98,7 @@ var webpackConfig = merge(baseWebpackConfig, { }), // 拷贝vendor.dll.js到构建目录 new CopyWebpackPlugin([ - { from: 'src/vendor.dll.js', to: 'static/js' } + { from: 'src/vendor_*.dll.js', to: 'static/js/[name].[ext]' } ]), new PrerenderSpaPlugin( path.join(__dirname, '../dist'), diff --git a/config/index.js b/config/index.js index 1650e75..6b79754 100644 --- a/config/index.js +++ b/config/index.js @@ -36,6 +36,6 @@ module.exports = { // (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. - cssSourceMap: false + cssSourceMap: true } } diff --git a/config/site.config.js b/config/site.config.js index 5f00ece..a8b3cba 100644 --- a/config/site.config.js +++ b/config/site.config.js @@ -3,7 +3,7 @@ * @desc 配置依赖服务器地址 * @type {{SERVER_ADDRESS: string, CENTER_ADDRESS: string, USERCENTER_ADDRESS: string, CDN_ADDRESS: string}} */ -const address = { +var address = { // api服务器 API_ADDRESS: 'http://192.168.26.119:1210', // API_ADDRESS: "http://192.168.23.224", diff --git a/index.html b/index.html index 388f8ed..d6b5a44 100644 --- a/index.html +++ b/index.html @@ -34,7 +34,8 @@ s.parentNode.insertBefore(hm, s); })(); - + + \ No newline at end of file diff --git a/src/service/api.js b/src/service/api.js index cfd9385..a6bb511 100644 --- a/src/service/api.js +++ b/src/service/api.js @@ -16,12 +16,12 @@ import { Message } from 'element-ui' var _this = Vue.prototype // 存放请求cancelToken - var apiCancelTokens=[] + var apiCancelTokens = [] // request请求拦截处理 Vue.axios.interceptors.request.use(function (config) { // 添加取消请求用的cancelToken - config.cancelToken=new Vue.axios.CancelToken(function executor(c) { - apiCancelTokens.push(c) + config.cancelToken = new Vue.axios.CancelToken(function executor(c) { + apiCancelTokens.push(c) }) return config }, function (error) { @@ -44,7 +44,7 @@ import { Message } from 'element-ui' // 如果请求未被取消,则处理错误信息 let msg = Message(`${err.config.apiName || '获取数据'}失败`) console.error(msg.message) - } + } return Promise.reject(err) }) @@ -53,13 +53,13 @@ import { Message } from 'element-ui' // 取消页面当前请求 apiRequsetCancel: function () { // 依次取消请求 - apiCancelTokens.forEach(function(cancel,k,s){cancel('请求被取消')}) + apiCancelTokens.forEach(function (cancel, k, s) { cancel('请求被取消') }) // 清空cancelToken - apiCancelTokens=[] + apiCancelTokens = [] }, topCarousel: function () { - return Vue.axios.get(`${API_ADDRESS2}/indexBanner.json`, { + return Vue.axios.get(`${API_ADDRESS2}/indexBanner1.json`, { apiName: '获取首页顶部banner' }) }, @@ -97,12 +97,12 @@ import { Message } from 'element-ui' username: user, password: pwd }, { - apiName: '用户登录' - }) + apiName: '用户登录' + }) }, // 获取RSA公钥 - getRSA: function(){ + getRSA: function () { return Vue.axios.get(`${API_ADDRESS}/getRSA`, { params: { t: Date.now() @@ -180,7 +180,7 @@ import { Message } from 'element-ui' return Vue.axios.post(`${API_ADDRESS}/surveyBill`, reqData) }, - detailedResearchReport () { + detailedResearchReport() { return Vue.axios.get(`/mock/detailedResearchReport.json`) },