-
Notifications
You must be signed in to change notification settings - Fork 143
/
Copy pathoptions.ts
94 lines (86 loc) · 3.95 KB
/
options.ts
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
84
85
86
87
88
89
90
91
92
93
94
export default interface Options {
/**
* When true, we statically resolve all components, modifiers, and helpers (collectively
* knows as Invokables) at build time. This causes any unused Invokables to be left out
* of the build if they are unused i.e. "tree shaking".
*
* Defaults to false which gives you greater compatibility with classic Ember apps at the
* cost of bigger builds.
*
* This setting takes over from `staticHelpers`, `staticModifiers`, and `staticComponents`
* because the Developer Experience was less than ideal if any of these settings did not
* agree i.e. they all needed to be true or they all needed to be false.
*
* Enabling this is a prerequisite for route splitting.
*/
staticInvokables?: boolean;
// Enables per-route code splitting. Any route names that match these patterns
// will be split out of the initial app payload. If you use this, you must
// also add @embroider/router to your app. See [@embroider/router's
// README](https://github.com/embroider-build/embroider/blob/main/packages/router/README.md)
splitAtRoutes?: (RegExp | string)[];
// Every file within your application's `app` directory is categorized as a
// component, helper, modifier, route, route template, controller, or "other".
//
// This option lets you decide which "other" files should be loaded
// statically. By default, all "other" files will be included in the build and
// registered with Ember's runtime loader, because we can't know if somebody
// is going to try to access them dynamically via Ember's resolver or AMD
// runtime `require`.
//
// If you know that your files are only ever imported, you can list them here
// and then they will only be included exactly where they're needed.
//
// Provide a list of directories or files relative to `/app`. For example
//
// staticAppPaths: ['lib']
//
// means that everything under your-project/app/lib will be loaded statically.
//
// This option has no effect on components (which are governed by
// staticComponents), helpers (which are governed by staticHelpers), modifiers
// (which are governed by staticModifiers) or the route-specific files (routes,
// route templates, and controllers which are governed by splitAtRoutes).
staticAppPaths?: string[];
// This is a performance optimization that can help you avoid the "Your build
// is slower because some babel plugins are non-serializable" penalty. If you
// provide the locations of known non-serializable objects, we can discover
// them and make them serializable.
//
// resolve is a list of paths to resolve, in a chain. This lets you resolve
// your dependencies' dependencies, like: resolve: ['your-dependency',
// 'inner-dependency/lib/transform']
//
// useMethod optionally lets you pick which property within the module to use.
// If not provided, we use the module.exports itself.
pluginHints?: { resolve: string[]; useMethod?: string }[];
}
export type CoreOptionsType = Required<Options>;
export function optionsWithDefaults(options?: Options): CoreOptionsType {
if ((options as any)?.staticHelpers !== undefined) {
throw new Error(
`You have set 'staticHelpers' on your Embroider options. This setting has been removed and replaced with 'staticInvokables'`
);
}
if ((options as any)?.staticComponents !== undefined) {
throw new Error(
`You have set 'staticComponents' on your Embroider options. This setting has been removed and replaced with 'staticInvokables'`
);
}
if ((options as any)?.staticModifiers !== undefined) {
throw new Error(
`You have set 'staticModifiers' on your Embroider options. This setting has been removed and replaced with 'staticInvokables'`
);
}
let defaults = {
staticInvokables: true,
splitAtRoutes: [],
staticAppPaths: [],
pluginHints: [],
amdCompatibility: 'cjs' as const,
};
if (options) {
return Object.assign(defaults, options);
}
return defaults;
}