Skip to content

Commit

Permalink
new: Update options for Babel plugins/presets. (#160)
Browse files Browse the repository at this point in the history
* Update options.

* Update tests.
  • Loading branch information
milesj authored Nov 1, 2022
1 parent d0d95f5 commit c47ff00
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
12 changes: 10 additions & 2 deletions packages/packemon/src/babel/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,18 +117,23 @@ export function getBabelInputConfig(
): Omit<ConfigStructure, 'exclude' | 'include'> {
const plugins: PluginItem[] = [];
const presets: PluginItem[] = [];
const tsOptions = {
allowDeclareFields: true,
onlyRemoveTypeImports: true,
optimizeConstEnums: true,
};

if (features.flow) {
presets.push([resolve('@babel/preset-flow'), { allowDeclareFields: true }]);
}

if (features.typescript) {
presets.push([resolve('@babel/preset-typescript'), { allowDeclareFields: true }]);
presets.push([resolve('@babel/preset-typescript'), tsOptions]);

// When decorators are used, class properties must be loose
if (features.decorators) {
plugins.push(
[resolve('@babel/plugin-transform-typescript'), { allowDeclareFields: true }],
[resolve('@babel/plugin-transform-typescript'), tsOptions],
[resolve('@babel/plugin-proposal-decorators'), { legacy: true }],
[resolveFromBabel('@babel/plugin-proposal-class-properties'), { loose: true }],
[resolveFromBabel('@babel/plugin-proposal-private-methods'), { loose: true }],
Expand All @@ -141,8 +146,11 @@ export function getBabelInputConfig(
presets.push([
resolve('@babel/preset-react'),
{
// development: __DEV__,
runtime: features.react,
throwIfNamespace: true,
useBuiltIns: true,
useSpread: true,
},
]);
}
Expand Down
14 changes: 14 additions & 0 deletions packages/packemon/tests/babel/__snapshots__/config.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ exports[`getBabelInputConfig() includes react preset if \`react\` feature flag i
{
"runtime": "classic",
"throwIfNamespace": true,
"useBuiltIns": true,
"useSpread": true,
},
],
]
Expand All @@ -84,6 +86,8 @@ exports[`getBabelInputConfig() includes react preset if \`react\` feature flag i
{
"runtime": "automatic",
"throwIfNamespace": true,
"useBuiltIns": true,
"useSpread": true,
},
],
]
Expand Down Expand Up @@ -112,6 +116,8 @@ exports[`getBabelInputConfig() includes typescript decorators if \`typescript\`
"@babel/plugin-transform-typescript",
{
"allowDeclareFields": true,
"onlyRemoveTypeImports": true,
"optimizeConstEnums": true,
},
],
[
Expand Down Expand Up @@ -144,6 +150,8 @@ exports[`getBabelInputConfig() includes typescript decorators if \`typescript\`
"@babel/preset-typescript",
{
"allowDeclareFields": true,
"onlyRemoveTypeImports": true,
"optimizeConstEnums": true,
},
],
],
Expand All @@ -156,6 +164,8 @@ exports[`getBabelInputConfig() includes typescript preset if \`typescript\` feat
"@babel/preset-typescript",
{
"allowDeclareFields": true,
"onlyRemoveTypeImports": true,
"optimizeConstEnums": true,
},
],
]
Expand All @@ -178,6 +188,8 @@ exports[`getBabelInputConfig() supports private properties with decorators if de
"@babel/plugin-transform-typescript",
{
"allowDeclareFields": true,
"onlyRemoveTypeImports": true,
"optimizeConstEnums": true,
},
],
[
Expand Down Expand Up @@ -210,6 +222,8 @@ exports[`getBabelInputConfig() supports private properties with decorators if de
"@babel/preset-typescript",
{
"allowDeclareFields": true,
"onlyRemoveTypeImports": true,
"optimizeConstEnums": true,
},
],
],
Expand Down

0 comments on commit c47ff00

Please sign in to comment.