options.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. scss: joi.object(),
  41. less: joi.object(),
  42. stylus: joi.object(),
  43. postcss: joi.object()
  44. })
  45. }),
  46. // webpack
  47. chainWebpack: joi.func(),
  48. configureWebpack: joi.alternatives().try(
  49. joi.object(),
  50. joi.func()
  51. ),
  52. // known runtime options for built-in plugins
  53. lintOnSave: joi.any().valid([true, false, 'error', 'warning', 'default']),
  54. pwa: joi.object(),
  55. // 3rd party plugin options
  56. pluginOptions: joi.object()
  57. }))
  58. exports.validate = (options, cb) => {
  59. validate(options, schema, cb)
  60. }
  61. // #2110
  62. // https://github.com/nodejs/node/issues/19022
  63. // in some cases cpus() returns undefined, and may simply throw in the future
  64. function hasMultipleCores () {
  65. try {
  66. return require('os').cpus().length > 1
  67. } catch (e) {
  68. return false
  69. }
  70. }
  71. exports.defaults = () => ({
  72. // project deployment base
  73. publicPath: '/',
  74. // for compatibility concern. TODO: remove in v4.
  75. baseUrl: '/',
  76. // where to output built files
  77. outputDir: 'dist',
  78. // where to put static assets (js/css/img/font/...)
  79. assetsDir: '',
  80. // filename for index.html (relative to outputDir)
  81. indexPath: 'index.html',
  82. // whether filename will contain hash part
  83. filenameHashing: true,
  84. // boolean, use full build?
  85. runtimeCompiler: false,
  86. // deps to transpile
  87. transpileDependencies: [
  88. /* string or regex */
  89. ],
  90. // sourceMap for production build?
  91. productionSourceMap: !process.env.VUE_CLI_TEST,
  92. // use thread-loader for babel & TS in production build
  93. // enabled by default if the machine has more than 1 cores
  94. parallel: hasMultipleCores(),
  95. // multi-page config
  96. pages: undefined,
  97. // <script type="module" crossorigin="use-credentials">
  98. // #1656, #1867, #2025
  99. crossorigin: undefined,
  100. // subresource integrity
  101. integrity: false,
  102. css: {
  103. // extract: true,
  104. // modules: false,
  105. // localIdentName: '[name]_[local]_[hash:base64:5]',
  106. // sourceMap: false,
  107. // loaderOptions: {}
  108. },
  109. // whether to use eslint-loader
  110. lintOnSave: true,
  111. devServer: {
  112. /*
  113. open: process.platform === 'darwin',
  114. host: '0.0.0.0',
  115. port: 8080,
  116. https: false,
  117. hotOnly: false,
  118. proxy: null, // string | Object
  119. before: app => {}
  120. */
  121. }
  122. })