vue.config.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. var webpack = require('webpack')
  2. // const UglifyPlugin = require('uglifyjs-webpack-plugin')
  3. // const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer')
  4. const { VantResolver } = require('unplugin-vue-components/resolvers')
  5. const ComponentsPlugin = require('unplugin-vue-components/webpack')
  6. let timeStamp = new Date().getTime()
  7. /**
  8. * @type {webpack.Configuration }
  9. */
  10. module.exports = {
  11. productionSourceMap: false,
  12. publicPath: process.env.NODE_ENV == 'production' ? './' : '/',
  13. devServer: {
  14. open: true,
  15. host: '0.0.0.0',
  16. port: 5666,
  17. openPage: '#/',
  18. before: app => { },
  19. },
  20. css: {
  21. loaderOptions: {
  22. stylus: {
  23. // @/ 是 src/ 的别名,想配的话可以alias上配
  24. import: '~@/assets/style/var.styl',
  25. },
  26. },
  27. extract: { // 打包后css文件名称添加时间戳
  28. filename: `css/[name].${timeStamp}.css`,
  29. chunkFilename: `css/[name].${timeStamp}.css`,
  30. },
  31. },
  32. configureWebpack: {
  33. output: { // 输出重构 打包编译后的js文件名称,添加时间戳.
  34. filename: `js/[name].${timeStamp}.js`,
  35. chunkFilename: `js/[name].${timeStamp}.js`,
  36. },
  37. plugins: [
  38. new webpack.optimize.LimitChunkCountPlugin({
  39. maxChunks: 1, // 来限制 chunk 的最大数量
  40. }),
  41. ComponentsPlugin({
  42. resolvers: [VantResolver()],
  43. }),
  44. ],
  45. },
  46. chainWebpack: config => {
  47. config.module
  48. .rule('robot')
  49. .test(/robot\..+\.js$/)
  50. .use('raw-loader')
  51. .loader('raw-loader')
  52. .options({
  53. esModule: false,
  54. })
  55. config.module.rule('js').exclude.add(/robot\..+\.js$/)
  56. config.plugin('preload')
  57. .tap(args => {
  58. args[0].fileBlacklist.push(/\.css/, /\.js/)
  59. return args
  60. })
  61. config.plugin('inline-source')
  62. .use(require('html-webpack-inline-source-plugin'))
  63. config
  64. .plugin('html')
  65. .tap(args => {
  66. args[0].title = 'JSON和PHP Array 互转'
  67. args[0].inlineSource = '(\.css|\.js$)'
  68. return args
  69. })
  70. },
  71. }