Skip to content

Commit a8e063e

Browse files
committed
Exclude typescript from play_bundle
Reduces minified `play_bundle.js` size from 4.59 MiB to 2.37 MiB.
1 parent 2fc2c48 commit a8e063e

File tree

4 files changed

+13
-2
lines changed

4 files changed

+13
-2
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"html-loader": "^0.5.5",
2626
"html-webpack-plugin": "^3.2.0",
2727
"monaco-editor-webpack-plugin": "^1.8.2",
28+
"node-libs-browser": "^2.2.1",
2829
"pnp-webpack-plugin": "^1.5.0",
2930
"prettier": "^1.19.1",
3031
"raw-loader": "^4.0.0",

src/playground/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import TSTLWorker = require("worker-loader?name=tstl.worker.js!./tstlWorker");
88
// @ts-ignore
99
import FengariWorker = require("worker-loader?name=fengari.worker.js!./fengariWorker");
1010

11-
import * as tstl from "typescript-to-lua/dist/LuaAST";
11+
import * as lua from "typescript-to-lua/dist/LuaAST";
1212

1313
const renderjson = require("renderjson");
1414
const tstlPackageJson = require("typescript-to-lua/package.json");
@@ -127,7 +127,7 @@ if (container && exampleLua && astLua) {
127127
astLua.appendChild(
128128
renderjson.set_show_to_level(1).set_replacer((name: string, val: any) => {
129129
if (name === "kind") {
130-
return tstl.SyntaxKind[val];
130+
return lua.SyntaxKind[val];
131131
}
132132
return val;
133133
})(event.data.luaAST),

webpack.config.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const HtmlWebpackPlugin = require("html-webpack-plugin");
55
const PnpWebpackPlugin = require("pnp-webpack-plugin");
66

77
const resolve = query => path.resolve(__dirname, query);
8+
const emptyModulePath = require.resolve("node-libs-browser/mock/empty.js");
89

910
/** @type {import("webpack").Configuration} */
1011
module.exports = {
@@ -56,5 +57,13 @@ module.exports = {
5657

5758
// Ignore pnpapi reference in patched typescript source
5859
new webpack.IgnorePlugin(/pnpapi/),
60+
61+
// Exclude `typescript` from `play_bundle` referenced from `typescript-to-lua/dist/LuaAST`
62+
new webpack.NormalModuleReplacementPlugin(/typescript/, resource => {
63+
const { issuer, compiler } = (resource.resourceResolveData && resource.resourceResolveData.context) || {};
64+
if (issuer === require.resolve("typescript-to-lua/dist/LuaAST") && compiler !== "worker") {
65+
resource.resource = emptyModulePath;
66+
}
67+
}),
5968
],
6069
};

yarn.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6353,6 +6353,7 @@ resolve@^1.13.1:
63536353
html-webpack-plugin: ^3.2.0
63546354
monaco-editor: ^0.19.3
63556355
monaco-editor-webpack-plugin: ^1.8.2
6356+
node-libs-browser: ^2.2.1
63566357
pnp-webpack-plugin: ^1.5.0
63576358
prettier: ^1.19.1
63586359
raw-loader: ^4.0.0

0 commit comments

Comments
 (0)