diff --git a/src/main-dev.js b/src/main-dev.js new file mode 100644 index 0000000..cfc0251 --- /dev/null +++ b/src/main-dev.js @@ -0,0 +1,56 @@ +import Vue from 'vue' +import App from './App.vue' +import router from './router/router' +import ElementUI from 'element-ui' +import 'element-ui/lib/theme-chalk/index.css' +import './assets/fonts/iconfont.css' +import './assets/css/globel.css' +import tableTree from 'vue-table-with-tree-grid' +import axios from 'axios' +import vueQuillEditor from 'vue-quill-editor' + +import 'quill/dist/quill.core.css' // import styles +import 'quill/dist/quill.snow.css' // for snow theme +import 'quill/dist/quill.bubble.css' // for bubble theme +import timeline from 'element-ui/lib/timeline' +import timelineItem from 'element-ui/lib/timeline-item' +// 进度条 +import NProgres from 'nprogress' +import 'nprogress/nprogress.css' + +Vue.use(timeline) +Vue.use(timelineItem) +Vue.use(vueQuillEditor) +Vue.component('table-tree', tableTree) +axios.defaults.baseURL = 'http://127.0.0.1:8888/api/private/v1/' +// 为每个ajax请求头挂一个 token 并加载进度条 +axios.interceptors.request.use(config => { + NProgres.start() + config.headers.Authorization = sessionStorage.getItem('token') + return config +}) +axios.interceptors.response.use(response => { + NProgres.done() + return response +}) + +Vue.filter('dataFormat', (time) => { + const dt = (new Date(time)) + const y = dt.getFullYear() + const m = (dt.getMonth() + 1 + '').padStart(2, '0') + const d = (dt.getDate() + '').padStart(2, '0') + const H = dt.getHours().toString().padStart(2, '0') + const i = dt.getMinutes().toString().padStart(2, '0') + const s = dt.getSeconds().toString().padStart(2, '0') + return `${y}-${m}-${d} ${H}:${i}:${s}` +}) + +Vue.prototype.$http = axios +Vue.use(ElementUI) + +Vue.config.productionTip = false + +new Vue({ + router, + render: h => h(App) +}).$mount('#app') diff --git a/src/main-prod.js b/src/main-prod.js new file mode 100644 index 0000000..cfc0251 --- /dev/null +++ b/src/main-prod.js @@ -0,0 +1,56 @@ +import Vue from 'vue' +import App from './App.vue' +import router from './router/router' +import ElementUI from 'element-ui' +import 'element-ui/lib/theme-chalk/index.css' +import './assets/fonts/iconfont.css' +import './assets/css/globel.css' +import tableTree from 'vue-table-with-tree-grid' +import axios from 'axios' +import vueQuillEditor from 'vue-quill-editor' + +import 'quill/dist/quill.core.css' // import styles +import 'quill/dist/quill.snow.css' // for snow theme +import 'quill/dist/quill.bubble.css' // for bubble theme +import timeline from 'element-ui/lib/timeline' +import timelineItem from 'element-ui/lib/timeline-item' +// 进度条 +import NProgres from 'nprogress' +import 'nprogress/nprogress.css' + +Vue.use(timeline) +Vue.use(timelineItem) +Vue.use(vueQuillEditor) +Vue.component('table-tree', tableTree) +axios.defaults.baseURL = 'http://127.0.0.1:8888/api/private/v1/' +// 为每个ajax请求头挂一个 token 并加载进度条 +axios.interceptors.request.use(config => { + NProgres.start() + config.headers.Authorization = sessionStorage.getItem('token') + return config +}) +axios.interceptors.response.use(response => { + NProgres.done() + return response +}) + +Vue.filter('dataFormat', (time) => { + const dt = (new Date(time)) + const y = dt.getFullYear() + const m = (dt.getMonth() + 1 + '').padStart(2, '0') + const d = (dt.getDate() + '').padStart(2, '0') + const H = dt.getHours().toString().padStart(2, '0') + const i = dt.getMinutes().toString().padStart(2, '0') + const s = dt.getSeconds().toString().padStart(2, '0') + return `${y}-${m}-${d} ${H}:${i}:${s}` +}) + +Vue.prototype.$http = axios +Vue.use(ElementUI) + +Vue.config.productionTip = false + +new Vue({ + router, + render: h => h(App) +}).$mount('#app') diff --git a/vue.config.js b/vue.config.js index a5bf827..b639875 100644 --- a/vue.config.js +++ b/vue.config.js @@ -2,5 +2,13 @@ module.exports = { devServer: { port: 8887, open: true + }, + chainWebpack: config => { + config.when(process.env.NODE_ENV === 'production', config => { + config.entry('app').clear().add('./src/main-prod.js') + }) + config.when(process.env.NODE_ENV === 'development', config => { + config.entry('add').clear().add('./src/main-dev.js') + }) } }