options.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. const { createSchema, validate } = require('@vue/cli-shared-utils')
  2. const schema = createSchema(joi => joi.object({
  3. baseUrl: joi.string().allow(''),
  4. publicPath: joi.string().allow(''),
  5. outputDir: joi.string(),
  6. assetsDir: joi.string().allow(''),
  7. indexPath: joi.string(),
  8. filenameHashing: joi.boolean(),
  9. runtimeCompiler: joi.boolean(),
  10. transpileDependencies: joi.array(),
  11. productionSourceMap: joi.boolean(),
  12. parallel: joi.alternatives().try([
  13. joi.boolean(),
  14. joi.number().integer()
  15. ]),
  16. devServer: joi.object(),
  17. pages: joi.object().pattern(
  18. /\w+/,
  19. joi.alternatives().try([
  20. joi.string().required(),
  21. joi.array().items(joi.string().required()),
  22. joi.object().keys({
  23. entry: joi.alternatives().try([
  24. joi.string().required(),
  25. joi.array().items(joi.string().required())
  26. ]).required()
  27. }).unknown(true)
  28. ])
  29. ),
  30. crossorigin: joi.string().valid(['', 'anonymous', 'use-credentials']),
  31. integrity: joi.boolean(),
  32. // css
  33. css: joi.object({
  34. modules: joi.boolean(),
  35. extract: joi.alternatives().try(joi.boolean(), joi.object()),
  36. sourceMap: joi.boolean(),
  37. loaderOptions: joi.object({
  38. css: joi.object(),
  39. sass: joi.object(),
  40. less: joi.object(),
  41. stylus: joi.object(),
  42. postcss: joi.object()
  43. })
  44. }),
  45. // webpack
  46. chainWebpack: joi.func(),
  47. configureWebpack: joi.alternatives().try(
  48. joi.object(),
  49. joi.func()
  50. ),
  51. // known runtime options for built-in plugins
  52. lintOnSave: joi.any().valid([true, false, 'error', 'warning', 'default']),
  53. pwa: joi.object(),
  54. // 3rd party plugin options
  55. pluginOptions: joi.object()
  56. }))
  57. exports.validate = (options, cb) => {
  58. validate(options, schema, cb)
  59. }
  60. // #2110
  61. // https://github.com/nodejs/node/issues/19022
  62. // in some cases cpus() returns undefined, and may simply throw in the future
  63. function hasMultipleCores () {
  64. try {
  65. return require('os').cpus().length > 1
  66. } catch (e) {
  67. return false
  68. }
  69. }
  70. exports.defaults = () => ({
  71. // project deployment base
  72. publicPath: '/',
  73. // for compatibility concern. TODO: remove in v4.
  74. baseUrl: '/',
  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. // localIdentName: '[name]_[local]_[hash:base64:5]',
  105. // sourceMap: false,
  106. // loaderOptions: {}
  107. },
  108. // whether to use eslint-loader
  109. lintOnSave: true,
  110. devServer: {
  111. /*
  112. open: process.platform === 'darwin',
  113. host: '0.0.0.0',
  114. port: 8080,
  115. https: false,
  116. hotOnly: false,
  117. proxy: null, // string | Object
  118. before: app => {}
  119. */
  120. }
  121. })