/
index.js
82 lines (69 loc) · 2.03 KB
/
index.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
import babelTranspiler from '../../transpilers/babel';
import jsonTranspiler from '../../transpilers/json';
import stylesTranspiler from '../../transpilers/style';
import sassTranspiler from '../../transpilers/sass';
import rawTranspiler from '../../transpilers/raw';
import stylusTranspiler from '../../transpilers/stylus';
import lessTranspiler from '../../transpilers/less';
import tsTranspiler from '../../transpilers/typescript';
import Preset from '../';
export default function initialize() {
const cxjsPreset = new Preset(
'cxjs',
['js', 'jsx', 'ts', 'tsx', 'json', 'less', 'scss', 'sass', 'styl', 'css'],
{},
{}
);
cxjsPreset.registerTranspiler(module => /\.jsx?$/.test(module.path), [
{
transpiler: babelTranspiler,
options: {
dynamicCSSModules: true,
},
},
]);
cxjsPreset.registerTranspiler(module => /\.tsx?$/.test(module.path), [
{ transpiler: tsTranspiler },
]);
cxjsPreset.registerTranspiler(module => /\.css$/.test(module.path), [
{ transpiler: stylesTranspiler },
]);
cxjsPreset.registerTranspiler(module => /\.json$/.test(module.path), [
{ transpiler: jsonTranspiler },
]);
const sassWithConfig = {
transpiler: sassTranspiler,
options: {},
};
const lessWithConfig = {
transpiler: lessTranspiler,
options: {},
};
const stylusWithConfig = {
transpiler: stylusTranspiler,
options: {},
};
const styles = {
css: [],
scss: [sassWithConfig],
sass: [sassWithConfig],
less: [lessWithConfig],
styl: [stylusWithConfig],
};
/**
* Registers transpilers for all different combinations
*
* @returns
*/
function registerStyleTranspilers() {
return Object.keys(styles).forEach(type => {
cxjsPreset.registerTranspiler(
module => new RegExp(`\\.${type}`).test(module.path),
[...styles[type], { transpiler: stylesTranspiler }]
);
});
}
registerStyleTranspilers();
cxjsPreset.registerTranspiler(() => true, [{ transpiler: rawTranspiler }]);
return cxjsPreset;
}