Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use SWC for compilation as it has better dead-code-elimination #1608

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 73 additions & 41 deletions packages/@glimmer-workspace/build/lib/config.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
/* eslint-disable no-console */
// @ts-check
import { existsSync, readFileSync } from 'node:fs';
import { createRequire } from 'node:module';
import { dirname, resolve } from 'node:path';
import { fileURLToPath } from 'node:url';

import replace from '@rollup/plugin-replace';
import terser from '@rollup/plugin-terser';
import * as insert from 'rollup-plugin-insert';
import rollupTS from 'rollup-plugin-ts';
import ts from 'typescript';

import inline from './inline.js';

const require = createRequire(import.meta.url);

// eslint-disable-next-line import/no-named-as-default-member
const { ModuleKind, ModuleResolutionKind, ScriptTarget, ImportsNotUsedAsValues } = ts;

Expand Down Expand Up @@ -86,26 +82,87 @@ export function typescript(pkg, config) {
},
};

/** @type {[string, object][]} */
const presets = [['@babel/preset-typescript', { allowDeclareFields: true }]];

const ts = tsconfig(typeScriptConfig);

/**
* TODO: migrate off of rollupTS, it has too many bugs
*/
return rollupTS({
transpiler: 'babel',
transpiler: 'swc',
transpileOnly: true,
babelConfig: {
presets,
plugins: [require.resolve('@glimmer/local-debug-babel-plugin')],
swcConfig: {
jsc: {
parser: {
syntax: 'typescript',
tsx: false,
},
target: 'es2022',
loose: false,
minify: {
compress: {
arguments: false,
arrows: true,
booleans: true,
booleans_as_integers: false,
collapse_vars: true,
comparisons: true,
computed_props: true,
conditionals: true,
dead_code: true,
directives: true,
drop_console: false,
drop_debugger: true,
evaluate: true,
expression: false,
hoist_funs: false,
hoist_props: true,
hoist_vars: false,
if_return: true,
join_vars: true,
keep_classnames: false,
keep_fargs: true,
keep_fnames: false,
keep_infinity: false,
loops: true,
negate_iife: true,
properties: true,
reduce_funcs: false,
reduce_vars: false,
side_effects: true,
switches: true,
typeofs: true,
unsafe: false,
unsafe_arrows: false,
unsafe_comps: false,
unsafe_Function: false,
unsafe_math: false,
unsafe_symbols: false,
unsafe_methods: false,
unsafe_proto: false,
unsafe_regexp: false,
unsafe_undefined: false,
unused: true,
const_to_let: true,
pristine_globals: true,
},
mangle: false,
},
transform: {
constModules: {
globals: {
debug: {
'import.meta.env.VM_LOCAL_DEV': 'false',
},
},
},
},
},
module: {
type: 'es6',
},
minify: false,
isModule: true,
},
/**
* This shouldn't be required, but it is.
* If we use @rollup/plugin-babel, we can remove this.
*/
browserslist: [`last 1 chrome versions`],
tsconfig: ts,
});
}
Expand Down Expand Up @@ -319,31 +376,6 @@ export class Package {
commonjs(),
nodeResolve(),
...this.replacements(env),
...(env === 'prod'
? [
terser({
module: true,
// to debug the output, uncomment this so you can read the
// identifiers, unchanged
// mangle: false,
compress: {
passes: 3,
},
}),
]
: [
terser({
module: true,
mangle: false,
compress: {
passes: 3,
},
format: {
comments: 'all',
beautify: true,
},
}),
]),
postcss(),
typescript(this.#package, {
target: ScriptTarget.ES2022,
Expand Down
2 changes: 2 additions & 0 deletions packages/@glimmer-workspace/build/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
"@rollup/plugin-node-resolve": "^15.2.3",
"@rollup/plugin-replace": "^5.0.5",
"@rollup/plugin-terser": "^0.4.4",
"@swc/core": "^1.7.26",
"@swc/helpers": "^0.5.13",
"eslint": "^8.52.0",
"eslint-plugin-import": "^2.29.0",
"eslint-plugin-json": "^3.1.0",
Expand Down
144 changes: 142 additions & 2 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading