options.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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.array(),
  10. productionSourceMap: joi.boolean(),
  11. parallel: joi.alternatives().try([
  12. joi.boolean(),
  13. joi.number().integer()
  14. ]),
  15. devServer: joi.object(),
  16. pages: joi.object().pattern(
  17. /\w+/,
  18. joi.alternatives().try([
  19. joi.string().required(),
  20. joi.array().items(joi.string().required()),
  21. joi.object().keys({
  22. entry: joi.alternatives().try([
  23. joi.string().required(),
  24. joi.array().items(joi.string().required())
  25. ]).required()
  26. }).unknown(true)
  27. ])
  28. ),
  29. crossorigin: joi.string().valid(['', 'anonymous', 'use-credentials']),
  30. integrity: joi.boolean(),
  31. // css
  32. css: joi.object({
  33. // TODO: deprecate this after joi 16 release
  34. modules: joi.boolean(),
  35. requireModuleExtension: joi.boolean(),
  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. // 3rd party plugin options
  57. pluginOptions: joi.object()
  58. }))
  59. exports.validate = (options, cb) => {
  60. validate(options, schema, cb)
  61. }
  62. // #2110
  63. // https://github.com/nodejs/node/issues/19022
  64. // in some cases cpus() returns undefined, and may simply throw in the future
  65. function hasMultipleCores () {
  66. try {
  67. return require('os').cpus().length > 1
  68. } catch (e) {
  69. return false
  70. }
  71. }
  72. exports.defaults = () => ({
  73. // project deployment base
  74. publicPath: '/',
  75. // where to output built files
  76. outputDir: 'dist',
  77. // where to put static assets (js/css/img/font/...)
  78. assetsDir: '',
  79. // filename for index.html (relative to outputDir)
  80. indexPath: 'index.html',
  81. // whether filename will contain hash part
  82. filenameHashing: true,
  83. // boolean, use full build?
  84. runtimeCompiler: false,
  85. // deps to transpile
  86. transpileDependencies: [
  87. /* string or regex */
  88. ],
  89. // sourceMap for production build?
  90. productionSourceMap: !process.env.VUE_CLI_TEST,
  91. // use thread-loader for babel & TS in production build
  92. // enabled by default if the machine has more than 1 cores
  93. parallel: hasMultipleCores(),
  94. // multi-page config
  95. pages: undefined,
  96. // <script type="module" crossorigin="use-credentials">
  97. // #1656, #1867, #2025
  98. crossorigin: undefined,
  99. // subresource integrity
  100. integrity: false,
  101. css: {
  102. // extract: true,
  103. // modules: false,
  104. // sourceMap: false,
  105. // loaderOptions: {}
  106. },
  107. // whether to use eslint-loader
  108. lintOnSave: 'default',
  109. devServer: {
  110. /*
  111. open: process.platform === 'darwin',
  112. host: '0.0.0.0',
  113. port: 8080,
  114. https: false,
  115. hotOnly: false,
  116. proxy: null, // string | Object
  117. before: app => {}
  118. */
  119. }
  120. })