Skip to content

Commit bb17ff5

Browse files
noahdarveau/Rollup changes for treeshaking (#2513)
* Added Rollup to the library to build a tree-shakable esm version of the library and updated pipeline appropriately.
1 parent 57ea793 commit bb17ff5

File tree

17 files changed

+987
-102
lines changed

17 files changed

+987
-102
lines changed

apps/teams-test-app/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"build:CDN": "pnpm lint && webpack --config webpack.cdn.config.js",
1111
"build:local": "pnpm lint && webpack --config webpack.local.config.js && pnpm copy",
1212
"clean": "rimraf ./build",
13-
"copy": "shx cp ../../packages/teams-js/dist/MicrosoftTeams.min.js ./build/ && shx cp ../../packages/teams-js/dist/MicrosoftTeams.min.js.map ./build/",
13+
"copy": "shx cp ../../packages/teams-js/dist/umd/MicrosoftTeams.min.js ./build/ && shx cp ../../packages/teams-js/dist/umd/MicrosoftTeams.min.js.map ./build/",
1414
"lint": "pnpm eslint ./src --max-warnings 0 --fix --ext .tsx",
1515
"start": "pnpm start:bundle",
1616
"start:bundle": "webpack serve",
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"name": "tree-shaking-test-app",
3+
"private": true,
4+
"author": "Noah",
5+
"description": "Test app to test the tree-shakability of TeamsJS",
6+
"version": "0.0.1",
7+
"main": "index.ts",
8+
"type": "module",
9+
"scripts": {
10+
"build-rollup": "pnpm clean && rollup --c",
11+
"build-webpack": "webpack",
12+
"clean": "rimraf ./dist"
13+
},
14+
"dependencies": {
15+
"@microsoft/teams-js": "workspace:*"
16+
},
17+
"devDependencies": {
18+
"@rollup/plugin-node-resolve": "^15.2.3",
19+
"@rollup/plugin-typescript": "^11.1.6",
20+
"@rollup/plugin-terser": "0.4.4",
21+
"rollup": "^4.18.0",
22+
"webpack": "^5.18.0",
23+
"webpack-cli": "^4.3.1",
24+
"testlibraryfortreeshaking": "^1.0.24"
25+
}
26+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { nodeResolve } from '@rollup/plugin-node-resolve';
2+
import terser from '@rollup/plugin-terser';
3+
import typescript from '@rollup/plugin-typescript';
4+
5+
// rollup.config.mjs
6+
export default {
7+
input: 'src/index.ts',
8+
output: [
9+
{
10+
file: 'dist/bundle.js',
11+
format: 'es',
12+
sourcemap: true,
13+
},
14+
{
15+
file: 'dist/bundle.min.js',
16+
format: 'es',
17+
plugins: [terser()],
18+
sourcemap: true,
19+
},
20+
],
21+
plugins: [
22+
nodeResolve({
23+
extension: ['.js', '.ts', '.d.ts', '.json'],
24+
}),
25+
typescript(),
26+
],
27+
treeshake: true,
28+
};
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { barCode } from 'testlibraryfortreeshaking';
2+
import { geoLocation } from '@microsoft/teams-js';
3+
barCode.hasPermission();
4+
geoLocation.requestPermission();
5+
geoLocation.map.isSupported();
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"compilerOptions": {
3+
"lib": ["dom", "dom.iterable", "esnext"],
4+
"allowJs": true,
5+
"allowSyntheticDefaultImports": true,
6+
"skipLibCheck": true,
7+
"esModuleInterop": true,
8+
"strict": true,
9+
"forceConsistentCasingInFileNames": true,
10+
"module": "es6",
11+
"moduleResolution": "node",
12+
"resolveJsonModule": true,
13+
"jsx": "react",
14+
"sourceMap": true,
15+
"outDir": "./dist"
16+
},
17+
"include": ["src"],
18+
"exclude": [
19+
"**/build/*",
20+
"build",
21+
"node_modules",
22+
"**/*.test.*",
23+
"webpack.config.js",
24+
"webpack.cdn.config.js",
25+
"webpack.cdnV1.config.js",
26+
"webpack.local.config.js"
27+
]
28+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/* eslint @typescript-eslint/no-var-requires: off*/
2+
/* eslint-disable no-undef */
3+
const path = require('path');
4+
5+
module.exports = {
6+
entry: './src/index.ts',
7+
output: {
8+
filename: 'index.js',
9+
path: path.resolve(__dirname, 'dist'),
10+
},
11+
mode: 'development',
12+
optimization: {
13+
usedExports: true,
14+
innerGraph: true,
15+
sideEffects: false,
16+
},
17+
devtool: false,
18+
module: {
19+
rules: [
20+
{
21+
test: /\.tsx?$/,
22+
use: 'ts-loader',
23+
exclude: /node_modules/,
24+
},
25+
],
26+
},
27+
resolve: {
28+
extensions: ['.tsx', '.ts', '.js'],
29+
},
30+
};

apps/typed-dependency-tester/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"version": "0.0.1",
77
"scripts": {
88
"build": "pnpm i && pnpm copy && pnpm tsc && pnpm clean",
9-
"copy": "cp ./node_modules/@microsoft/teams-js/dist/MicrosoftTeams.d.ts ./ || xcopy .\\node_modules\\@microsoft\\teams-js\\dist\\MicrosoftTeams.d.ts .\\ /Y",
9+
"copy": "cp ./node_modules/@microsoft/teams-js/dist/umd/MicrosoftTeams.d.ts ./ || xcopy .\\node_modules\\@microsoft\\teams-js\\dist\\umd\\MicrosoftTeams.d.ts .\\ /Y",
1010
"clean": "rimraf node_modules && rimraf MicrosoftTeams.d.ts"
1111
},
1212
"dependencies": {},
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "minor",
3+
"comment": "Added a Rollup built bundle of Teams-JS",
4+
"packageName": "@microsoft/teams-js",
5+
"email": "[email protected]",
6+
"dependentChangeType": "patch"
7+
}

package.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@
4141
"@mixer/webpack-bundle-compare": "^0.1.1",
4242
"@next/eslint-plugin-next": "^14.2.4",
4343
"@octokit/core": "^3.6.0",
44+
"@rollup/plugin-commonjs": "^26.0.1",
45+
"@rollup/plugin-json": "^6.1.0",
46+
"@rollup/plugin-node-resolve": "^15.2.3",
47+
"@rollup/plugin-replace": "5.0.7",
48+
"@rollup/plugin-terser": "0.4.4",
49+
"@rollup/plugin-typescript": "^11.1.6",
4450
"@types/fs-extra": "^9.0.13",
4551
"@types/jest": "^27.5.2",
4652
"@types/jscodeshift": "^0.11.11",
@@ -80,9 +86,12 @@
8086
"path": "^0.12.7",
8187
"prettier": "^3.3.2",
8288
"rimraf": "^5.0.7",
89+
"rollup": "^3.21.0",
90+
"rollup-plugin-polyfill-node": "^0.13.0",
8391
"shx": "^0.3.4",
8492
"style-loader": "^3.3.4",
8593
"ts-jest": "^29.1.2",
94+
"tslib": "^2.3.1",
8695
"ts-loader": "^9.5.1",
8796
"ts-node": "^10.9.2",
8897
"typedoc": "^0.24.8",
File renamed without changes.

0 commit comments

Comments
 (0)