UNPKG

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