vue.config.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. const path = require('path');
  2. function resolve(dir) {
  3. return path.join(__dirname, dir);
  4. }
  5. const cdn = {
  6. js: [
  7. // vue 必须优先加载(生产环境使用最小运行时版本runtime.min, 其他环境使用全版本)
  8. process.env.NODE_ENV !== 'production' ?
  9. 'https://cdn.bootcss.com/vue/2.6.10/vue.js' : 'https://cdn.bootcss.com/vue/2.6.9/vue.runtime.min.js',
  10. // vue-router
  11. 'https://cdn.bootcss.com/vue-router/3.0.6/vue-router.min.js',
  12. // element js
  13. 'https://unpkg.com/element-ui/lib/index.js'
  14. ],
  15. css: [
  16. // element css
  17. 'https://unpkg.com/element-ui/lib/theme-chalk/index.css'
  18. ]
  19. };
  20. module.exports = {
  21. lintOnSave: false,
  22. publicPath: process.env.NODE_ENV === 'production' ? './' : '/',
  23.     assetsDir: 'public',
  24.     outputDir: 'dist',
  25. chainWebpack: (config) => {
  26. // 通过 html-webpack-plugin注入到 index.html
  27. config.plugin('html').tap(args => {
  28. args[0].cdn = cdn;
  29. return args;
  30. });
  31. },
  32. configureWebpack: {
  33. resolve: {
  34. alias: {
  35. '@': resolve('src'),
  36. 'view': resolve('src/view'),
  37. 'assets': resolve('src/assets'),
  38. 'common': resolve('src/common')
  39. }
  40. },
  41. externals: {
  42. Vue: 'vue',
  43. 'router': 'router',
  44. 'ElementUI': 'element-ui'
  45. }
  46. },
  47. devServer: {
  48. host: '0.0.0.0',
  49. port: 8080,
  50. https: false,
  51. hotOnly: false,
  52. proxy: null, // 设置代理
  53. before: () => {}
  54. }
  55. };