Skip to content

Commit a3a4403

Browse files
authored
[Blazor] Update other packages to bundle with rollup (#53117)
* Updated all other "JS" packages in compoents to bundle with rollup instead of webpack. * CustomElements uses "ES" format as its a JSInitializer. * AuthenticationService for msal and webassembly auth use "iife" format (immediately invoked function expression) since that's what's backwards compatible with the way they were imported.
1 parent 2683808 commit a3a4403

File tree

13 files changed

+289
-387
lines changed

13 files changed

+289
-387
lines changed

package-lock.json

Lines changed: 24 additions & 176 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Components/CustomElements/src/js/package.json

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,18 @@
55
"clean": "rimraf ./dist/Debug ./dist/Release",
66
"prebuild": "npm run clean",
77
"build": "npm run build:debug && npm run build:production",
8-
"build:debug": "webpack --mode development --config ./webpack.config.js",
9-
"build:production": "webpack --mode production --config ./webpack.config.js"
8+
"build:debug": "rollup -c --environment development --forceExit",
9+
"build:production": "rollup -c --environment production --forceExit"
1010
},
1111
"devDependencies": {
12-
"@babel/core": "^7.15.0",
13-
"@babel/preset-env": "^7.15.0",
14-
"@typescript-eslint/eslint-plugin": "^5.26.0",
15-
"@typescript-eslint/parser": "^5.26.0",
16-
"eslint": "^8.16.0",
17-
"inspectpack": "^4.7.1",
12+
"@rollup/plugin-commonjs": "^25.0.7",
13+
"@rollup/plugin-node-resolve": "^15.2.3",
14+
"@rollup/plugin-replace": "^5.0.5",
15+
"@rollup/plugin-terser": "^0.4.4",
16+
"@rollup/plugin-typescript": "^11.1.5",
1817
"rimraf": "^3.0.2",
19-
"terser": "^5.14.2",
20-
"ts-loader": "^9.2.5",
21-
"typescript": "^4.4.2",
22-
"webpack": "^5.72.1",
23-
"webpack-cli": "^4.9.2"
24-
},
25-
"resolutions": {
26-
"ansi-regex": "5.0.1",
27-
"minimist": ">=1.2.6"
18+
"rollup": "^4.9.2",
19+
"rollup-plugin-filesize": "^10.0.0",
20+
"typescript": "^5.3.3"
2821
}
2922
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import path from 'path';
2+
import typescript from '@rollup/plugin-typescript';
3+
import terser from '@rollup/plugin-terser';
4+
import resolve from '@rollup/plugin-node-resolve';
5+
import commonjs from '@rollup/plugin-commonjs';
6+
import replace from '@rollup/plugin-replace';
7+
import filesize from 'rollup-plugin-filesize';
8+
import { fileURLToPath } from 'url';
9+
10+
const __filename = fileURLToPath(import.meta.url);
11+
const __dirname = path.dirname(__filename);
12+
13+
console.log(__dirname);
14+
15+
export default ({ environment }) => {
16+
17+
var inputOutputMap = {
18+
'Microsoft.AspNetCore.Components.CustomElements.lib.module': './BlazorCustomElements.ts',
19+
};
20+
21+
/**
22+
* @type {import('rollup').RollupOptions}
23+
*/
24+
const baseConfig = {
25+
output: {
26+
dir: path.join(__dirname, '/dist', environment === 'development' ? '/Debug' : '/Release'),
27+
format: 'es',
28+
sourcemap: true,
29+
entryFileNames: '[name].js',
30+
sourcemap: environment === 'development' ? 'inline' : false,
31+
},
32+
plugins: [
33+
resolve(),
34+
commonjs(),
35+
typescript({
36+
tsconfig: path.join(__dirname, 'tsconfig.json')
37+
}),
38+
replace({
39+
'process.env.NODE_DEBUG': 'false',
40+
'Platform.isNode': 'false',
41+
preventAssignment: true
42+
}),
43+
terser({
44+
compress: {
45+
passes: 3
46+
},
47+
mangle: true,
48+
module: false,
49+
format: {
50+
ecma: 2020
51+
},
52+
keep_classnames: false,
53+
keep_fnames: false,
54+
toplevel: true
55+
})
56+
,
57+
environment !== 'development' && filesize({ showMinifiedSize: true, showGzippedSize: true, showBrotliSize: true })
58+
],
59+
treeshake: 'smallest',
60+
logLevel: 'silent'
61+
};
62+
63+
return Object.entries(inputOutputMap).map(([output, input]) => {
64+
const config = {
65+
...baseConfig,
66+
output: {
67+
...baseConfig.output,
68+
},
69+
input: { [output]: input }
70+
};
71+
72+
return config;
73+
});
74+
};
Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
{
22
"compilerOptions": {
3-
"target": "ES2019",
4-
"module": "commonjs",
5-
"lib": [ "DOM", "ES2019" ],
6-
"sourceMap": true,
3+
"target": "ES2022",
4+
"module": "ESNext",
5+
"lib": [ "DOM", "ES2022" ],
76
"strict": true,
8-
"esModuleInterop": true,
97
"forceConsistentCasingInFileNames": true
108
}
119
}

0 commit comments

Comments
 (0)