vue.config.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. 'use strict';
  2. const path = require('path');
  3. const webpack = require('webpack');
  4. const CompressionPlugin = require('compression-webpack-plugin');
  5. const HtmlWebpackPlugin = require('html-webpack-plugin');
  6. function resolve(dir) {
  7. return path.join(__dirname, dir);
  8. }
  9. const name = 'st vue'; // page title
  10. const port = 9000; // dev port
  11. // All configuration item explanations can be find in https://cli.vuejs.org/config/
  12. module.exports = {
  13. publicPath: process.env.PUBLIC_PATH,
  14. // publicPath: process.env.NODE_ENV === 'production'
  15. // ? secondaryPath
  16. // : process.env.PUBLIC_PATH, // des: 部署应用包时的基本 二级目录时开启此处 URL author: wxy data: 2019/12/30
  17. // publicPath: './', //vueConf.baseUrl, // 根域上下文目录
  18. outputDir: 'dist', // 构建输出目录
  19. assetsDir: process.env.ASSETS_DIR,
  20. // assetsDir: './', // 静态资源目录 (js, css, img, fonts)
  21. lintOnSave: true, // 是否开启eslint保存检测,有效值:ture | false | 'error'
  22. runtimeCompiler: true, // 运行时版本是否需要编译
  23. transpileDependencies: [], // 默认babel-loader忽略modealias_modules,这里可增加例外的依赖包名
  24. productionSourceMap: false, // 是否在构建生产包时生成 sourceMap 文件,false将提高构建速度
  25. devServer: {
  26. port: port,
  27. open: true,
  28. overlay: {
  29. warnings: false,
  30. errors: true,
  31. },
  32. proxy: {
  33. // change xxx-api/login => mock/login
  34. // detail: https://cli.vuejs.org/config/#devserver-proxy
  35. [process.env.VUE_APP_BASE_API]: {
  36. target: process.env.VUE_APP_BASE_API_TARGET,
  37. changeOrigin: true,
  38. pathRewrite: {
  39. ['^' + process.env.VUE_APP_BASE_API]: '',
  40. },
  41. },
  42. },
  43. },
  44. pwa: {
  45. iconPaths: {
  46. favicon32: process.env.VUE_APP_INDEX_TINY_ICON,
  47. favicon16: process.env.VUE_APP_INDEX_TINY_ICON,
  48. appleTouchIcon: process.env.VUE_APP_INDEX_TINY_ICON,
  49. maskIcon: process.env.VUE_APP_INDEX_TINY_ICON,
  50. msTileImage: process.env.VUE_APP_INDEX_TINY_ICON,
  51. },
  52. },
  53. chainWebpack: config => {
  54. config.resolve.alias
  55. .set('@', path.resolve(__dirname, './src'))
  56. .set('excelVendor', path.resolve(__dirname, './src/utils/excelVendor'));
  57. config.plugins.delete('preload');
  58. config.plugins.delete('prefetch');
  59. config.plugin('provide')
  60. .use(webpack.ProvidePlugin, [
  61. {
  62. 'window.Quill': 'quill',
  63. introJs: 'intro.js',
  64. },
  65. ]);
  66. },
  67. configureWebpack: config => {
  68. Object.assign(config, {
  69. name: name,
  70. // 开发生产共同配置
  71. });
  72. if (process.env.ENV === 'production') {
  73. let cssFilesArr = [
  74. `external/kityformula/kityformula/assets/styles/base.css`,
  75. `external/kityformula/kityformula/assets/styles/ui.css`,
  76. `external/kityformula/kityformula/assets/styles/scrollbar.css`,
  77. ];
  78. let jsFilesArr = [
  79. `external/js/vue@2.6.10.js`,
  80. `external/js/vue-router@3.1.3.js`,
  81. `external/js/element-ui@2.12.0.js`,
  82. `external/js/echarts@4.2.1.js`,
  83. `external/js/aliyun-upload-sdk/lib/es6-promise.min.js`,
  84. `external/js/aliyun-upload-sdk/lib/aliyun-oss-sdk-5.3.1.min.js`,
  85. `external/js/aliyun-upload-sdk/aliyun-upload-sdk-1.5.0.min.js`,
  86. `external/kityformula/kityformula/js/jquery-1.11.0.min.js`,
  87. `external/kityformula/kityformula/js/kitygraph.all.js`,
  88. `external/kityformula/kityformula/js/kity-formula-render.all.js`,
  89. `external/kityformula/kityformula/js/kity-formula-parser.all.min.js`,
  90. `external/kityformula/kityformula/js/kityformula-editor.all.min.js`,
  91. ];
  92. // 为生产环境修改配置...
  93. config.mode = 'production';
  94. Object.assign(config, {
  95. externals: {
  96. 'vue-router': 'VueRouter',
  97. 'element-ui': 'ELEMENT',
  98. 'echarts': 'echarts',
  99. 'vue': 'Vue',
  100. // 'vuex': 'Vuex'
  101. },
  102. plugins: [
  103. ...config.plugins,
  104. new HtmlWebpackPlugin({
  105. template: path.join(__dirname, './src/utils/st/index.html'),//指定模板页面,根据指定的路径生成内存中的页面
  106. templateParameters: {
  107. 'BASE_URL': process.env.PUBLIC_PATH,
  108. 'VUE_APP_INDEX_TINY_ICON': process.env.VUE_APP_INDEX_TINY_ICON,
  109. 'VUE_APP_INDEX_TITLE': process.env.VUE_APP_INDEX_TITLE,
  110. 'cssVendor': cssFilesArr,
  111. 'jsVendor': jsFilesArr,
  112. },
  113. filename: 'index.html', //指定内存中生成的页面的名称
  114. /* inject: true,
  115. favicon: process.env.BASE_URL+ 'favicon-saas.ico'*/
  116. }),
  117. new CompressionPlugin({
  118. test: /\.js$|\.html$|.\css/, // 匹配文件名 ttf
  119. threshold: 10240, // 对超过10k的数据压缩
  120. deleteOriginalAssets: false, // 不删除源文件
  121. }),
  122. ],
  123. });
  124. } else {
  125. // 为开发环境修改配置...
  126. config.mode = 'development';
  127. }
  128. },
  129. css: {
  130. // 当为true时,css文件名可省略 module 默认为 false
  131. modules: false,
  132. // 是否将组件中的 CSS 提取至一个独立的 CSS 文件中,当作为一个库构建时,你也可以将其设置为 false 免得用户自己导入 CSS
  133. // 默认生产环境下是 true,开发环境下是 false
  134. extract: false,
  135. // 是否为 CSS 开启 source map。设置为 true 之后可能会影响构建的性能
  136. sourceMap: false,
  137. //向 CSS 相关的 loader 传递选项(支持 css-loader postcss-loader sass-loader less-loader stylus-loader)
  138. loaderOptions: {
  139. css: {},
  140. less: {},
  141. sass: {
  142. /*data: `@import "@/assets/css/main.scss";`*/
  143. },
  144. },
  145. },
  146. /*configureWebpack: {
  147. // provide the app's title in webpack's name field, so that
  148. // it can be accessed in index.html to inject the correct title.
  149. name: name,
  150. resolve: {
  151. alias: {
  152. '@': resolve('src'),
  153. 'excelVendor': resolve('src/utils/excelVendor'),
  154. },
  155. },
  156. externals: {
  157. 'vue': 'Vue',
  158. 'vue-router': 'VueRouter',
  159. 'element-ui': 'ELEMENT',
  160. 'echarts': 'echarts',
  161. },
  162. plugins: [
  163. new CompressionPlugin({
  164. test: /\.js$|\.html$|.\css/, // 匹配文件名 ttf
  165. threshold: 10240, // 对超过10k的数据压缩
  166. deleteOriginalAssets: false, // 不删除源文件
  167. }),
  168. ],
  169. },*/
  170. /*chainWebpack(config) {
  171. const cdn = {
  172. // inject tinymce into index.html
  173. // why use this cdn, detail see https://github.com/PanJiaChen/tinymce-all-in-one
  174. js: ['https://cdn.jsdelivr.net/npm/tinymce-all-in-one@4.9.3/tinymce.min.js']
  175. }
  176. config.plugin('html')
  177. .tap(args => {
  178. args[0].cdn = cdn
  179. return args
  180. })
  181. config.plugins.delete('preload') // TODO: need test
  182. config.plugins.delete('prefetch') // TODO: need test
  183. // set svg-sprite-loader
  184. config.module
  185. .rule('svg')
  186. .exclude.add(resolve('src/icons'))
  187. .end()
  188. config.module
  189. .rule('icons')
  190. .test(/\.svg$/)
  191. .include.add(resolve('src/icons'))
  192. .end()
  193. .use('svg-sprite-loader')
  194. .loader('svg-sprite-loader')
  195. .options({
  196. symbolId: 'icon-[name]'
  197. })
  198. .end()
  199. // set preserveWhitespace
  200. config.module
  201. .rule('vue')
  202. .use('vue-loader')
  203. .loader('vue-loader')
  204. .tap(options => {
  205. options.compilerOptions.preserveWhitespace = true
  206. return options
  207. })
  208. .end()
  209. config
  210. // https://webpack.js.org/configuration/devtool/#development
  211. .when(process.env.ENV === 'development',
  212. config => config.devtool('cheap-source-map')
  213. )
  214. config
  215. .when(process.env.ENV !== 'development',
  216. config => {
  217. config
  218. .plugin('ScriptExtHtmlWebpackPlugin')
  219. .after('html')
  220. .use('script-ext-html-webpack-plugin', [{
  221. // `runtime` must same as runtimeChunk name. default is `runtime`
  222. inline: /runtime\..*\.js$/
  223. }])
  224. .end()
  225. config
  226. .optimization.splitChunks({
  227. chunks: 'all',
  228. cacheGroups: {
  229. libs: {
  230. name: 'chunk-libs',
  231. test: /[\\/]node_modules[\\/]/,
  232. priority: 10,
  233. chunks: 'initial' // only package third parties that are initially dependent
  234. },
  235. elementUI: {
  236. name: 'chunk-elementUI', // split elementUI into a single package
  237. priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app
  238. test: /[\\/]node_modules[\\/]_?element-ui(.*)/ // in order to adapt to cnpm
  239. },
  240. commons: {
  241. name: 'chunk-commons',
  242. test: resolve('src/components'), // can customize your rules
  243. minChunks: 3, // minimum common number
  244. priority: 5,
  245. reuseExistingChunk: true
  246. }
  247. }
  248. })
  249. config.optimization.runtimeChunk('single')
  250. }
  251. )
  252. }*/
  253. };