options.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. const { createSchema, validate } = require('@vue/cli-shared-utils')
  2. const schema = createSchema(joi => joi.object({
  3. publicPath: joi.string().allow(''),
  4. outputDir: joi.string(),
  5. assetsDir: joi.string().allow(''),
  6. indexPath: joi.string(),
  7. filenameHashing: joi.boolean(),
  8. runtimeCompiler: joi.boolean(),
  9. transpileDependencies: joi.alternatives().try(
  10. joi.boolean(),
  11. joi.array()
  12. ),
  13. productionSourceMap: joi.boolean(),
  14. parallel: joi.alternatives().try(
  15. joi.boolean(),
  16. joi.number().integer()
  17. ),
  18. devServer: joi.object(),
  19. pages: joi.object().pattern(
  20. /\w+/,
  21. joi.alternatives().try(
  22. joi.string().required(),
  23. joi.array().items(joi.string().required()),
  24. joi.object().keys({
  25. entry: joi.alternatives().try(
  26. joi.string().required(),
  27. joi.array().items(joi.string().required())
  28. ).required()
  29. }).unknown(true)
  30. )
  31. ),
  32. crossorigin: joi.string().valid('', 'anonymous', 'use-credentials'),
  33. integrity: joi.boolean(),
  34. // css
  35. css: joi.object({
  36. extract: joi.alternatives().try(joi.boolean(), joi.object()),
  37. sourceMap: joi.boolean(),
  38. loaderOptions: joi.object({
  39. css: joi.object(),
  40. sass: joi.object(),
  41. scss: joi.object(),
  42. less: joi.object(),
  43. stylus: joi.object(),
  44. postcss: joi.object()
  45. })
  46. }),
  47. // webpack
  48. chainWebpack: joi.func(),
  49. configureWebpack: joi.alternatives().try(
  50. joi.object(),
  51. joi.func()
  52. ),
  53. // known runtime options for built-in plugins
  54. lintOnSave: joi.any().valid(true, false, 'error', 'warning', 'default'),
  55. pwa: joi.object(),
  56. // terser
  57. terser: joi.object({
  58. minify: joi.string().valid('terser', 'esbuild', 'swc', 'uglifyJs'),
  59. terserOptions: joi.object()
  60. }),
  61. // 3rd party plugin options
  62. pluginOptions: joi.object()
  63. }))
  64. exports.validate = (options, cb) => {
  65. validate(options, schema, cb)
  66. }
  67. // #2110
  68. // https://github.com/nodejs/node/issues/19022
  69. // in some cases cpus() returns undefined, and may simply throw in the future
  70. function hasMultipleCores () {
  71. try {
  72. return require('os').cpus().length > 1
  73. } catch (e) {
  74. return false
  75. }
  76. }
  77. exports.defaults = () => ({
  78. // project deployment base
  79. publicPath: '/',
  80. // where to output built files
  81. outputDir: 'dist',
  82. // where to put static assets (js/css/img/font/...)
  83. assetsDir: '',
  84. // filename for index.html (relative to outputDir)
  85. indexPath: 'index.html',
  86. // whether filename will contain hash part
  87. filenameHashing: true,
  88. // boolean, use full build?
  89. runtimeCompiler: false,
  90. // whether to transpile all dependencies
  91. transpileDependencies: false,
  92. // sourceMap for production build?
  93. productionSourceMap: !process.env.VUE_CLI_TEST,
  94. // use thread-loader for babel & TS in production build
  95. // enabled by default if the machine has more than 1 cores
  96. parallel: hasMultipleCores(),
  97. // multi-page config
  98. pages: undefined,
  99. // <script type="module" crossorigin="use-credentials">
  100. // #1656, #1867, #2025
  101. crossorigin: undefined,
  102. // subresource integrity
  103. integrity: false,
  104. css: {
  105. // extract: true,
  106. // modules: false,
  107. // sourceMap: false,
  108. // loaderOptions: {}
  109. },
  110. // whether to use eslint-loader
  111. lintOnSave: 'default',
  112. devServer: {
  113. /*
  114. open: process.platform === 'darwin',
  115. host: '0.0.0.0',
  116. port: 8080,
  117. https: false,
  118. hotOnly: false,
  119. proxy: null, // string | Object
  120. before: app => {}
  121. */
  122. }
  123. })