vue.config.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. const path = require('path')
  2. const CopyWebpackPlugin = require('copy-webpack-plugin')
  3. function resolve(dir) {
  4. return path.join(__dirname, dir)
  5. }
  6. const projectName = process.env.PROJECT
  7. const port = process.env.port || process.env.npm_config_port || 9527
  8. const publicDir = 'src/projects/' + projectName + '/public/'
  9. const settings = require('./src/projects/' + projectName + '/settings.js')
  10. module.exports = {
  11. outputDir: '../../public/' + projectName,
  12. publicPath: '/' + projectName + '/',
  13. assetsDir: 'static',
  14. lintOnSave: process.env.NODE_ENV === 'development',
  15. productionSourceMap: false,
  16. devServer: {
  17. port: port,
  18. // open: true,
  19. overlay: {
  20. warnings: false,
  21. errors: true
  22. }
  23. },
  24. css: {
  25. loaderOptions: {
  26. postcss: {
  27. plugins: [require('tailwindcss'), require('autoprefixer')]
  28. }
  29. }
  30. },
  31. configureWebpack: {
  32. name: settings.title,
  33. externals: {
  34. jquery: "jQuery",
  35. },
  36. resolve: {
  37. alias: {
  38. '@@': resolve('src'),
  39. '@': resolve('src/projects/' + projectName)
  40. }
  41. },
  42. // configure public as a static assets folder
  43. plugins: [
  44. new CopyWebpackPlugin([{ from: publicDir, to: '', toType: 'dir' }])
  45. ],
  46. performance: {
  47. hints: 'warning',
  48. maxEntrypointSize: 50000000,
  49. maxAssetSize: 30000000,
  50. assetFilter: function(assetFilename) {
  51. return assetFilename.endsWith('.js')
  52. }
  53. }
  54. },
  55. chainWebpack(config) {
  56. config.plugin('preload').tap(() => [
  57. {
  58. rel: 'preload',
  59. // to ignore runtime.js
  60. fileBlacklist: [/\.map$/, /hot-update\.js$/, /runtime\..*\.js$/],
  61. include: 'initial'
  62. }
  63. ])
  64. // when there are many pages, it will cause too many meaningless requests
  65. config.plugins.delete('prefetch')
  66. // to configure public as the location of the template
  67. config.plugin('html').tap(args => {
  68. args[0].template = path.resolve(publicDir + '/index.html')
  69. return args
  70. })
  71. }
  72. }