Skip to content

Commit 7c5b80c

Browse files
[release/6.0] [SignalR] Only minify .min.js files (#39859)
* [SignalR] Only minify .min.js files * test Co-authored-by: Brennan <[email protected]>
1 parent 4ea6623 commit 7c5b80c

File tree

4 files changed

+37
-10
lines changed

4 files changed

+37
-10
lines changed

src/SignalR/clients/ts/signalr/package.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,12 @@
1616
"preclean": "cd ../common && yarn install --mutex network --frozen-lockfile",
1717
"clean": "node ../common/node_modules/rimraf/bin.js ./dist",
1818
"prebuild": "yarn run clean && yarn install --mutex network --frozen-lockfile",
19-
"build": "yarn run build:lint && yarn run build:esm && yarn run build:cjs && yarn run build:browser && yarn run build:webworker && yarn run build:uglify",
19+
"build": "yarn run build:lint && yarn run build:esm && yarn run build:cjs && yarn run build:browser && yarn run build:webworker",
2020
"build:lint": "node ../common/node_modules/eslint/bin/eslint ./src --ext .ts --resolve-plugins-relative-to ../common",
2121
"build:esm": "node ../common/node_modules/typescript/bin/tsc --project ./tsconfig.json --module es2015 --outDir ./dist/esm -d && node ./build/process-dts.js",
2222
"build:cjs": "node ../common/node_modules/typescript/bin/tsc --project ./tsconfig.json --module commonjs --outDir ./dist/cjs",
2323
"build:browser": "node ../common/node_modules/webpack-cli/bin/cli.js",
2424
"build:webworker": "node ../common/node_modules/webpack-cli/bin/cli.js --env platform=webworker",
25-
"build:uglify": "yarn run build:uglify:browser && yarn run build:uglify:webworker",
26-
"build:uglify:browser": "node ../common/node_modules/terser/bin/terser -m -c --ecma 2019 --module --source-map \"url='signalr.min.js.map',content='./dist/browser/signalr.js.map'\" --comments -o ./dist/browser/signalr.min.js ./dist/browser/signalr.js",
27-
"build:uglify:webworker": "node ../common/node_modules/terser/bin/terser -m -c --ecma 2019 --module--source-map \"url='signalr.min.js.map',content='./dist/webworker/signalr.js.map'\" --comments -o ./dist/webworker/signalr.min.js ./dist/webworker/signalr.js",
2825
"prepack": "node ../build/embed-version.js",
2926
"test": "echo \"Run 'yarn test' in the 'clients/ts' folder to test this package\" && exit 1"
3027
},
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
import * as _fs from "fs";
5+
import * as path from "path";
6+
import { promisify } from "util";
7+
8+
const fs = {
9+
stat: promisify(_fs.stat),
10+
};
11+
12+
// Regression tests to make sure we are building the .min and non .min js files differently.
13+
// It's ok to have to modify these values as long as we know why they changed.
14+
15+
describe("Output files", () => {
16+
it(".min.js file is small", async () => {
17+
const size = await (await fs.stat(path.resolve(__dirname, "..", "dist/browser/signalr.min.js"))).size;
18+
expect(size).toBeLessThan(45000);
19+
});
20+
21+
it("non .min.js file is big", async () => {
22+
const size = await (await fs.stat(path.resolve(__dirname, "..", "dist/browser/signalr.js"))).size;
23+
expect(size).toBeGreaterThan(120000);
24+
});
25+
});

src/SignalR/clients/ts/signalr/webpack.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ const baseConfig = require("../webpack.config.base");
44
module.exports = env => baseConfig(__dirname, "signalr", {
55
// These are only used in Node environments
66
// so we tell webpack not to pull them in for the browser
7-
target: env && env.platform ? env.platform : undefined,
8-
platformDist: env && env.platform ? env.platform : undefined,
7+
target: env && env.platform ? env.platform : undefined,
8+
platformDist: env && env.platform ? env.platform : undefined,
99
externals: [
1010
"ws",
1111
"eventsource",

src/SignalR/clients/ts/webpack.config.base.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ module.exports = function (modulePath, browserBaseName, options) {
1111

1212
options = options || {};
1313

14-
return {
15-
entry: path.resolve(modulePath, "src", "browser-index.ts"),
14+
const webpackOptions = {
15+
entry: {},
1616
mode: "none",
1717
node: {
1818
global: true
@@ -45,7 +45,7 @@ module.exports = function (modulePath, browserBaseName, options) {
4545
}
4646
},
4747
output: {
48-
filename: `${browserBaseName}.js`,
48+
filename: '[name].js',
4949
path: path.resolve(modulePath, "dist", options.platformDist || "browser"),
5050
library: {
5151
root: pkg.umd_name.split("."),
@@ -55,7 +55,7 @@ module.exports = function (modulePath, browserBaseName, options) {
5555
},
5656
plugins: [
5757
new webpack.SourceMapDevToolPlugin({
58-
filename: `${browserBaseName}.js.map`,
58+
filename: '[name].js.map',
5959
moduleFilenameTemplate(info) {
6060
let resourcePath = info.resourcePath;
6161

@@ -88,6 +88,7 @@ module.exports = function (modulePath, browserBaseName, options) {
8888
innerGraph: true,
8989
minimize: true,
9090
minimizer: [new TerserJsPlugin({
91+
include: /\.min\.js$/,
9192
terserOptions: {
9293
ecma: 2019,
9394
compress: {},
@@ -114,4 +115,8 @@ module.exports = function (modulePath, browserBaseName, options) {
114115
},
115116
externals: options.externals,
116117
};
118+
119+
webpackOptions.entry[browserBaseName] = path.resolve(modulePath, "src", "browser-index.ts");
120+
webpackOptions.entry[`${browserBaseName}.min`] = path.resolve(modulePath, "src", "browser-index.ts");
121+
return webpackOptions;
117122
}

0 commit comments

Comments
 (0)