Skip to content
Merged
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
5 changes: 1 addition & 4 deletions src/SignalR/clients/ts/signalr/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,12 @@
"preclean": "cd ../common && yarn install --mutex network --frozen-lockfile",
"clean": "node ../common/node_modules/rimraf/bin.js ./dist",
"prebuild": "yarn run clean && yarn install --mutex network --frozen-lockfile",
"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",
"build": "yarn run build:lint && yarn run build:esm && yarn run build:cjs && yarn run build:browser && yarn run build:webworker",
"build:lint": "node ../common/node_modules/eslint/bin/eslint ./src --ext .ts --resolve-plugins-relative-to ../common",
"build:esm": "node ../common/node_modules/typescript/bin/tsc --project ./tsconfig.json --module es2015 --outDir ./dist/esm -d && node ./build/process-dts.js",
"build:cjs": "node ../common/node_modules/typescript/bin/tsc --project ./tsconfig.json --module commonjs --outDir ./dist/cjs",
"build:browser": "node ../common/node_modules/webpack-cli/bin/cli.js",
"build:webworker": "node ../common/node_modules/webpack-cli/bin/cli.js --env platform=webworker",
"build:uglify": "yarn run build:uglify:browser && yarn run build:uglify:webworker",
"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",
"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",
"prepack": "node ../build/embed-version.js",
"test": "echo \"Run 'yarn test' in the 'clients/ts' folder to test this package\" && exit 1"
},
Expand Down
25 changes: 25 additions & 0 deletions src/SignalR/clients/ts/signalr/tests/OutputSize.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

import * as _fs from "fs";
import * as path from "path";
import { promisify } from "util";

const fs = {
stat: promisify(_fs.stat),
};

// Regression tests to make sure we are building the .min and non .min js files differently.
// It's ok to have to modify these values as long as we know why they changed.

describe("Output files", () => {
it(".min.js file is small", async () => {
const size = await (await fs.stat(path.resolve(__dirname, "..", "dist/browser/signalr.min.js"))).size;
expect(size).toBeLessThan(45000);
});

it("non .min.js file is big", async () => {
const size = await (await fs.stat(path.resolve(__dirname, "..", "dist/browser/signalr.js"))).size;
expect(size).toBeGreaterThan(120000);
});
});
4 changes: 2 additions & 2 deletions src/SignalR/clients/ts/signalr/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ const baseConfig = require("../webpack.config.base");
module.exports = env => baseConfig(__dirname, "signalr", {
// These are only used in Node environments
// so we tell webpack not to pull them in for the browser
target: env && env.platform ? env.platform : undefined,
platformDist: env && env.platform ? env.platform : undefined,
target: env && env.platform ? env.platform : undefined,
platformDist: env && env.platform ? env.platform : undefined,
externals: [
"ws",
"eventsource",
Expand Down
13 changes: 9 additions & 4 deletions src/SignalR/clients/ts/webpack.config.base.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ module.exports = function (modulePath, browserBaseName, options) {

options = options || {};

return {
entry: path.resolve(modulePath, "src", "browser-index.ts"),
const webpackOptions = {
entry: {},
mode: "none",
node: {
global: true
Expand Down Expand Up @@ -45,7 +45,7 @@ module.exports = function (modulePath, browserBaseName, options) {
}
},
output: {
filename: `${browserBaseName}.js`,
filename: '[name].js',
path: path.resolve(modulePath, "dist", options.platformDist || "browser"),
library: {
root: pkg.umd_name.split("."),
Expand All @@ -55,7 +55,7 @@ module.exports = function (modulePath, browserBaseName, options) {
},
plugins: [
new webpack.SourceMapDevToolPlugin({
filename: `${browserBaseName}.js.map`,
filename: '[name].js.map',
moduleFilenameTemplate(info) {
let resourcePath = info.resourcePath;

Expand Down Expand Up @@ -88,6 +88,7 @@ module.exports = function (modulePath, browserBaseName, options) {
innerGraph: true,
minimize: true,
minimizer: [new TerserJsPlugin({
include: /\.min\.js$/,
terserOptions: {
ecma: 2019,
compress: {},
Expand All @@ -114,4 +115,8 @@ module.exports = function (modulePath, browserBaseName, options) {
},
externals: options.externals,
};

webpackOptions.entry[browserBaseName] = path.resolve(modulePath, "src", "browser-index.ts");
webpackOptions.entry[`${browserBaseName}.min`] = path.resolve(modulePath, "src", "browser-index.ts");
return webpackOptions;
}