Skip to content

Commit

Permalink
TGUI: Replaces babel & terser (#6196)
Browse files Browse the repository at this point in the history
<!-- Write **BELOW** The Headers and **ABOVE** The comments else it may
not be viewable. -->

# About the pull request
Replaces tgui build tools with faster alternatives.

There were some issues in build of components using hooks which do not
exist, which I removed as well. This is not a required part of the PR
but React does not use these

Based on two PRs: 
[Esbuild](tgstation/tgstation#79916)
[SWC](tgstation/tgstation#80310)

<!-- Remove this text and explain what the purpose of your PR is.

Mention if you have tested your changes. If you changed a map, make sure
you used the mapmerge tool.
If this is an Issue Correction, you can type "Fixes Issue #169420" to
link the PR to the corresponding Issue number #169420.

Remember: something that is self-evident to you might not be to others.
Explain your rationale fully, even if you feel it goes without saying.
-->

# Explain why it's good for the game
Faster build times
<!-- Please add a short description of why you think these changes would
benefit the game. If you can't justify it in words, it might not be
worth adding, and may discourage maintainers from reviewing or merging
your PR. This section is not strictly required for (non-controversial)
fix PRs or backend PRs. -->


# Testing Photographs and Procedure
<!-- Include any screenshots/videos/debugging steps of the modified code
functioning successfully, ideally including edge cases. -->


<!-- !! If you are modifying sprites, you **must** include one or more
in-game screenshots or videos of the new sprites. !! -->

<details>
<summary>Screenshots & Videos</summary>

Before
![Screenshot 2024-04-26
155554](https://github.com/cmss13-devs/cmss13/assets/42397676/5a48687e-dc6e-43d7-98d9-354bd3848ff6)

After
![Screenshot 2024-04-26
160516](https://github.com/cmss13-devs/cmss13/assets/42397676/b106ad86-25db-4403-b80a-29f4cd1ca38d)

</details>
  • Loading branch information
jlsnow301 authored May 1, 2024
1 parent 8bf5fb2 commit e556b32
Show file tree
Hide file tree
Showing 15 changed files with 626 additions and 1,600 deletions.
15 changes: 15 additions & 0 deletions tgui/.swcrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"$schema": "https://json.schemastore.org/swcrc",
"jsc": {
"loose": true,
"parser": {
"syntax": "typescript",
"tsx": true
},
"transform": {
"react": {
"runtime": "automatic"
}
}
}
}
52 changes: 0 additions & 52 deletions tgui/babel.config.js

This file was deleted.

2 changes: 1 addition & 1 deletion tgui/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module.exports = {
testEnvironment: 'jsdom',
testRunner: require.resolve('jest-circus/runner'),
transform: {
'^.+\\.(js|cjs|ts|tsx)$': require.resolve('babel-jest'),
'^.+\\.(js|cjs|ts|tsx)$': require.resolve('@swc/jest'),
},
moduleFileExtensions: ['js', 'cjs', 'ts', 'tsx', 'json'],
resetMocks: true,
Expand Down
16 changes: 4 additions & 12 deletions tgui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,16 @@
"tgui:tsc": "tsc"
},
"dependencies": {
"@babel/core": "^7.15.0",
"@babel/eslint-parser": "^7.15.0",
"@babel/plugin-transform-class-properties": "^7.23.3",
"@babel/plugin-transform-jscript": "^7.14.5",
"@babel/preset-env": "^7.15.0",
"@babel/preset-react": "^7.23.3",
"@babel/preset-typescript": "^7.15.0",
"@swc/core": "^1.5.0",
"@swc/jest": "^0.2.36",
"@types/jest": "^27.0.1",
"@types/jsdom": "^16.2.13",
"@types/node": "^14.17.9",
"@types/webpack": "^5.28.0",
"@types/webpack-env": "^1.16.2",
"@typescript-eslint/parser": "^4.29.1",
"babel-jest": "^27.0.6",
"babel-loader": "^8.2.2",
"babel-plugin-transform-remove-console": "^6.9.4",
"common": "workspace:*",
"css-loader": "^5.2.7",
"esbuild-loader": "^4.1.0",
"eslint": "^7.32.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-radar": "^0.2.1",
Expand All @@ -52,7 +44,7 @@
"sass": "^1.37.5",
"sass-loader": "^11.1.1",
"style-loader": "^2.0.0",
"terser-webpack-plugin": "^5.1.4",
"swc-loader": "^0.2.6",
"typescript": "^4.9.4",
"url-loader": "^4.1.1",
"webpack": "^5.75.0",
Expand Down
4 changes: 1 addition & 3 deletions tgui/packages/tgui/components/Button.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

import { KEY_ENTER, KEY_ESCAPE, KEY_SPACE } from 'common/keycodes';
import { classes, pureComponentHooks } from 'common/react';
import { classes } from 'common/react';
import { Component, createRef } from 'react';
import { createLogger } from '../logging';
import { Box, computeBoxClassName, computeBoxProps } from './Box';
Expand Down Expand Up @@ -134,8 +134,6 @@ export const Button = (props) => {
return buttonContent;
};

Button.defaultHooks = pureComponentHooks;

export const ButtonCheckbox = (props) => {
const { checked, ...rest } = props;
return (
Expand Down
3 changes: 0 additions & 3 deletions tgui/packages/tgui/components/Chart.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*/

import { map, zipWith } from 'common/collections';
import { pureComponentHooks } from 'common/react';
import { Component, createRef } from 'react';
import { Box } from './Box';

Expand Down Expand Up @@ -117,8 +116,6 @@ class LineChart extends Component {
}
}

LineChart.defaultHooks = pureComponentHooks;

const Stub = (props) => null;

// IE8: No inline svg support
Expand Down
4 changes: 1 addition & 3 deletions tgui/packages/tgui/components/ColorBox.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @license MIT
*/

import { classes, pureComponentHooks } from 'common/react';
import { classes } from 'common/react';
import { computeBoxClassName, computeBoxProps } from './Box';

export const ColorBox = (props) => {
Expand All @@ -27,5 +27,3 @@ export const ColorBox = (props) => {
</div>
);
};

ColorBox.defaultHooks = pureComponentHooks;
2 changes: 0 additions & 2 deletions tgui/packages/tgui/components/DraggableControl.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*/

import { clamp } from 'common/math';
import { pureComponentHooks } from 'common/react';
import { Component, createRef } from 'react';
import { AnimatedNumber } from './AnimatedNumber';

Expand Down Expand Up @@ -276,7 +275,6 @@ export class DraggableControl extends Component {
}
}

DraggableControl.defaultHooks = pureComponentHooks;
DraggableControl.defaultProps = {
minValue: -Infinity,
maxValue: +Infinity,
Expand Down
5 changes: 0 additions & 5 deletions tgui/packages/tgui/components/Grid.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*/

import { Table } from './Table';
import { pureComponentHooks } from 'common/react';

/** @deprecated */
export const Grid = (props) => {
Expand All @@ -17,8 +16,6 @@ export const Grid = (props) => {
);
};

Grid.defaultHooks = pureComponentHooks;

/** @deprecated */
export const GridColumn = (props) => {
const { size = 1, style, ...rest } = props;
Expand All @@ -33,6 +30,4 @@ export const GridColumn = (props) => {
);
};

Grid.defaultHooks = pureComponentHooks;

Grid.Column = GridColumn;
4 changes: 1 addition & 3 deletions tgui/packages/tgui/components/Icon.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* @license MIT
*/

import { classes, pureComponentHooks } from 'common/react';
import { classes } from 'common/react';
import { computeBoxClassName, computeBoxProps } from './Box';

const FA_OUTLINE_REGEX = /-o$/;
Expand Down Expand Up @@ -55,8 +55,6 @@ export const Icon = (props) => {
);
};

Icon.defaultHooks = pureComponentHooks;

export const IconStack = (props) => {
const { className, children, ...rest } = props;
return (
Expand Down
4 changes: 1 addition & 3 deletions tgui/packages/tgui/components/NoticeBox.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @license MIT
*/

import { classes, pureComponentHooks } from 'common/react';
import { classes } from 'common/react';
import { Box } from './Box';

export const NoticeBox = (props) => {
Expand All @@ -23,5 +23,3 @@ export const NoticeBox = (props) => {
/>
);
};

NoticeBox.defaultHooks = pureComponentHooks;
8 changes: 1 addition & 7 deletions tgui/packages/tgui/components/Table.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @license MIT
*/

import { classes, pureComponentHooks } from 'common/react';
import { classes } from 'common/react';
import { computeBoxClassName, computeBoxProps } from './Box';

export const Table = (props) => {
Expand All @@ -23,8 +23,6 @@ export const Table = (props) => {
);
};

Table.defaultHooks = pureComponentHooks;

export const TableRow = (props) => {
const { className, header, ...rest } = props;
return (
Expand All @@ -40,8 +38,6 @@ export const TableRow = (props) => {
);
};

TableRow.defaultHooks = pureComponentHooks;

export const TableCell = (props) => {
const { className, collapsing, header, ...rest } = props;
return (
Expand All @@ -58,7 +54,5 @@ export const TableCell = (props) => {
);
};

TableCell.defaultHooks = pureComponentHooks;

Table.Row = TableRow;
Table.Cell = TableCell;
3 changes: 1 addition & 2 deletions tgui/public/tgui-panel.bundle.css

Large diffs are not rendered by default.

37 changes: 9 additions & 28 deletions tgui/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
const webpack = require('webpack');
const path = require('path');
const ExtractCssPlugin = require('mini-css-extract-plugin');
const { createBabelConfig } = require('./babel.config.js');

const createStats = (verbose) => ({
assets: verbose,
Expand All @@ -33,18 +32,9 @@ module.exports = (env = {}, argv) => {
context: path.resolve(__dirname),
target: ['web', 'es3', 'browserslist:ie 8'],
entry: {
'tgui': [
'./packages/tgui-polyfill',
'./packages/tgui',
],
'tgui-panel': [
'./packages/tgui-polyfill',
'./packages/tgui-panel',
],
'tgui-say': [
'./packages/tgui-polyfill',
'./packages/tgui-say',
],
'tgui': ['./packages/tgui-polyfill', './packages/tgui'],
'tgui-panel': ['./packages/tgui-polyfill', './packages/tgui-panel'],
'tgui-say': ['./packages/tgui-polyfill', './packages/tgui-say'],
},
output: {
path: argv.useTmpFolder
Expand All @@ -61,13 +51,10 @@ module.exports = (env = {}, argv) => {
module: {
rules: [
{
test: /\.(js|jsx|cjs|ts|tsx)$/,
test: /\.([tj]s(x)?|cjs)$/,
use: [
{
loader: require.resolve('babel-loader'),
options: createBabelConfig({
removeConsole: !bench,
}),
loader: require.resolve('swc-loader'),
},
],
},
Expand Down Expand Up @@ -143,17 +130,11 @@ module.exports = (env = {}, argv) => {

// Production build specific options
if (mode === 'production') {
const TerserPlugin = require('terser-webpack-plugin');
const { EsbuildPlugin } = require('esbuild-loader');
config.optimization.minimizer = [
new TerserPlugin({
extractComments: false,
terserOptions: {
ie8: true,
output: {
ascii_only: true,
comments: false,
},
},
new EsbuildPlugin({
target: 'ie8',
css: true,
}),
];
}
Expand Down
Loading

0 comments on commit e556b32

Please sign in to comment.