-
Notifications
You must be signed in to change notification settings - Fork 18
/
loadConfig.js
83 lines (66 loc) · 2.13 KB
/
loadConfig.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
const path = require('path');
Object.defineProperty(exports, '__esModule', { value: true });
const CONFIG_FILES = ['.svelterc', 'svelte.config.js'];
const CONFIG_PACKAGE_KEY = 'svelte';
async function getConfigFile(config) {
const packageKey = CONFIG_PACKAGE_KEY;
const file = await config.getConfig(CONFIG_FILES, { packageKey });
return file || null;
}
async function configHydrator(configFile, config, options) {
config.setResult({
raw: configFile,
hydrated: {
preprocess: configFile.preprocess,
},
});
}
exports.load = async function load({ config, options, logger }) {
const configFile = await getConfigFile(config);
if (!configFile) return;
const { contents } = configFile;
const isDynamic = path.extname(configFile.filePath) === '.js';
if (typeof contents !== 'object' && typeof contents !== 'string') {
throw new Error('Svelte config should be an object or a string.');
}
if (isDynamic) {
if (!contents.preprocess) {
logger.warn({
message:
'WARNING: Using a JavaScript Svelte config file means losing out on caching features of Parcel. Use a .svelterc(.json) file whenever possible.',
});
}
config.invalidateOnStartup();
}
if (contents.compiler) {
logger.warn({
message:
'WARNING: The "compiler" option in .svelterc is deprecated, use "compilerOptions" instead',
});
contents.compilerOptions = contents.compilerOptions || contents.compiler;
}
return configHydrator(
{
compilerOptions: {
css: false,
...contents.compilerOptions,
dev: options.mode !== 'production',
},
preprocess: contents.preprocess,
},
config,
options,
);
};
exports.preSerialize = function preSerialize(config) {
if (!config.result) return;
// Ensure we don't pass preprocess functions to the serializer
if (config.result.raw.preprocess) {
config.result.raw = {};
}
// This gets re-hydrated in Deserialize, so never store this
config.result.hydrated = {};
};
exports.postDeserialize = function postDeserialize(config, options) {
return configHydrator(config.result.raw, config, options);
};