-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
index.js
72 lines (62 loc) · 1.89 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
import { join, absolute } from '@codesandbox/common/lib/utils/path';
import Preset from '..';
import typescriptTranspiler from '../../transpilers/typescript';
import rawTranspiler from '../../transpilers/raw';
import jsonTranspiler from '../../transpilers/json';
import stylesTranspiler from '../../transpilers/style';
import dojoStylesTranspiler from './transpilers/style';
import babelTranspiler from '../../transpilers/babel';
export default function initialize() {
const preset = new Preset(
'@dojo/cli-create-app',
['ts', 'tsx', 'js', 'json'],
{},
{
setup: async manager => {
const stylesPath = absolute(join('src', 'main.css'));
try {
const tModule = await manager.resolveTranspiledModuleAsync(
stylesPath,
null
);
await tModule.transpile(manager);
tModule.setIsEntry(true);
tModule.evaluate(manager);
} catch (e) {
if (e.type === 'module-not-found') {
// Do nothing
} else {
throw e;
}
}
},
}
);
preset.registerTranspiler(module => /\.tsx?$/.test(module.path), [
{ transpiler: typescriptTranspiler },
]);
preset.registerTranspiler(module => /\.jsx?$/.test(module.path), [
{
transpiler: babelTranspiler,
options: {
isV7: true,
config: {
parserOpts: {
plugins: ['objectRestSpread'],
},
},
},
},
]);
preset.registerTranspiler(module => /\.json$/.test(module.path), [
{ transpiler: jsonTranspiler },
]);
preset.registerTranspiler(module => /\.m\.css$/.test(module.path), [
{ transpiler: dojoStylesTranspiler },
]);
preset.registerTranspiler(module => /\.css$/.test(module.path), [
{ transpiler: stylesTranspiler },
]);
preset.registerTranspiler(() => true, [{ transpiler: rawTranspiler }]);
return preset;
}