-
Notifications
You must be signed in to change notification settings - Fork 0
/
svelte.config.js
47 lines (44 loc) · 1.29 KB
/
svelte.config.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
// svelte options exported for svelte-vscode
const {
preprocess: makeTsPreprocess,
createEnv,
readConfigFile,
} = require("@pyoner/svelte-ts-preprocess");
const less = require('less');
const env = createEnv();
const compilerOptions = readConfigFile(env);
const preprocessOptions = {
env,
compilerOptions: {
...compilerOptions,
allowNonTsExtensions: true,
},
};
module.exports = {
dev: !(['development', 'dev'].includes(process.env.NODE_ENV)),
preprocess:{
...makeTsPreprocess(preprocessOptions),
postcss: {
plugins: [require('autoprefixer')()]
},
// svelte 内部 style 可以引入 less
style: async ({ content, attributes, filename }) => {
if(!(attributes.type === 'text/less' || attributes.lang === 'less' )) {
return;
}
try {
const { css, map, imports } = await less.render(content, {
sourceMap: {sourceMapFileInline: true},
filename
});
return {
code: css.toString('utf8'),
map: map.toString('utf8'),
dependencies: imports
}
} catch (e) {
return e;
}
}
},
};