Skip to content

Commit d77f562

Browse files
committed
Centralize build configuration
1 parent 3c68915 commit d77f562

File tree

13 files changed

+141
-297
lines changed

13 files changed

+141
-297
lines changed
Lines changed: 9 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,16 @@
11
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';
82
import { fileURLToPath } from 'url';
3+
import createBaseConfig from '../../../Shared.JS/rollup.config.mjs';
94

105
const __filename = fileURLToPath(import.meta.url);
116
const __dirname = path.dirname(__filename);
127

13-
console.log(__dirname);
14-
15-
export default ({ environment }) => {
16-
17-
var inputOutputMap = {
8+
export default createBaseConfig({
9+
inputOutputMap: {
1810
'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-
};
11+
},
12+
dir: __dirname,
13+
updateConfig: (config, environment, _, input) => {
14+
config.output.format = 'es';
15+
}
16+
});
Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
11
{
2-
"compilerOptions": {
3-
"target": "ES2022",
4-
"module": "ESNext",
5-
"lib": [ "DOM", "ES2022" ],
6-
"strict": true,
7-
"forceConsistentCasingInFileNames": true
8-
}
2+
"extends": "../../../Shared.JS/tsconfig.json",
93
}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
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 { env } from 'process';
9+
10+
/**
11+
* @callback UpdateConfigFunction
12+
* @param {import('rollup').RollupOptions} config - The Rollup configuration to update.
13+
* @param {'development' | 'production' } environment - The environment we are compiling for ().
14+
* @param {string} output - The bundle we are generating.
15+
* @param {string} input - The entry point for the bundle.
16+
*/
17+
18+
/**
19+
* @typedef {Object} BaseOptions
20+
* @property {Object.<string, string>} inputOutputMap - An object that maps a string key to a string.
21+
* @property {string} dir - The directory for the config that we are creating.
22+
* @property {UpdateConfigFunction} updateConfig - A function that updates the configuration.
23+
*/
24+
25+
/**
26+
*
27+
* @param {BaseOptions} options
28+
* @returns
29+
*/
30+
export default function createBaseConfig({ inputOutputMap, dir, updateConfig }) {
31+
32+
return ({ environment }) => {
33+
34+
/**
35+
* @type {import('rollup').RollupOptions}
36+
*/
37+
const baseConfig = {
38+
output: {
39+
dir: path.join(dir, '/dist', environment === 'development' ? '/Debug' : '/Release'),
40+
format: 'cjs',
41+
sourcemap: environment === 'development' ? true : false,
42+
entryFileNames: '[name].js',
43+
},
44+
plugins: [
45+
resolve(),
46+
commonjs(),
47+
typescript({
48+
tsconfig: path.join(dir, 'tsconfig.json')
49+
}),
50+
replace({
51+
'process.env.NODE_DEBUG': 'false',
52+
'Platform.isNode': 'false',
53+
preventAssignment: true
54+
}),
55+
terser({
56+
compress: {
57+
passes: 3
58+
},
59+
mangle: true,
60+
module: false,
61+
format: {
62+
ecma: 2020
63+
},
64+
keep_classnames: false,
65+
keep_fnames: false,
66+
toplevel: true
67+
})
68+
,
69+
environment !== 'development' && filesize({ showMinifiedSize: true, showGzippedSize: true, showBrotliSize: true })
70+
],
71+
treeshake: 'smallest',
72+
logLevel: 'silent'
73+
};
74+
75+
return Object.entries(inputOutputMap).map(([output, input]) => {
76+
const config = {
77+
...baseConfig,
78+
output: {
79+
...baseConfig.output,
80+
},
81+
input: { [output]: input }
82+
};
83+
84+
updateConfig(config, environment, output, input);
85+
86+
return config;
87+
});
88+
};
89+
};
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"compilerOptions": {
3+
"target": "ES2022",
4+
"module": "ESNext",
5+
"lib": [ "DOM", "ES2022" ],
6+
"strict": true,
7+
"forceConsistentCasingInFileNames": true
8+
}
9+
}

src/Components/Web.JS/dist/Release/blazor.server.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Components/Web.JS/dist/Release/blazor.web.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Components/Web.JS/dist/Release/blazor.webview.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 8 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,20 @@
11
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';
82
import { fileURLToPath } from 'url';
93

104
const __filename = fileURLToPath(import.meta.url);
115
const __dirname = path.dirname(__filename);
126

13-
console.log(__dirname);
7+
import createBaseConfig from '../Shared.JS/rollup.config.mjs';
148

15-
export default ({ environment }) => {
16-
17-
var inputOutputMap = {
9+
export default createBaseConfig({
10+
inputOutputMap: {
1811
'blazor.server': './src/Boot.Server.ts',
1912
'blazor.web': './src/Boot.Web.ts',
2013
'blazor.webassembly': './src/Boot.WebAssembly.ts',
2114
'blazor.webview': './src/Boot.WebView.ts',
22-
};
23-
24-
/**
25-
* @type {import('rollup').RollupOptions}
26-
*/
27-
const baseConfig = {
28-
output: {
29-
dir: path.join(__dirname, '/dist', environment === 'development' ? '/Debug' : '/Release'),
30-
format: 'cjs',
31-
sourcemap: true,
32-
entryFileNames: '[name].js',
33-
},
34-
plugins: [
35-
resolve(),
36-
commonjs(),
37-
typescript({
38-
tsconfig: path.join(__dirname, 'tsconfig.json')
39-
}),
40-
replace({
41-
'process.env.NODE_DEBUG': 'false',
42-
'Platform.isNode': 'false',
43-
preventAssignment: true
44-
}),
45-
terser({
46-
compress: {
47-
passes: 3
48-
},
49-
mangle: true,
50-
module: false,
51-
format: {
52-
ecma: 2020
53-
},
54-
keep_classnames: false,
55-
keep_fnames: false,
56-
toplevel: true
57-
})
58-
,
59-
environment !== 'development' && filesize({ showMinifiedSize: true, showGzippedSize: true, showBrotliSize: true })
60-
],
61-
treeshake: 'smallest',
62-
logLevel: 'silent'
63-
};
64-
65-
return Object.entries(inputOutputMap).map(([output, input]) => {
66-
const config = {
67-
...baseConfig,
68-
output: {
69-
...baseConfig.output,
70-
},
71-
input: { [output]: input }
72-
};
73-
15+
},
16+
dir: __dirname,
17+
updateConfig: (config, environment, _, input) => {
7418
if (environment === 'development') {
7519
if (input.includes("WebView")) {
7620
config.output.sourcemap = 'inline';
@@ -80,7 +24,5 @@ export default ({ environment }) => {
8024
} else {
8125
config.output.sourcemap = false;
8226
}
83-
84-
return config;
85-
});
86-
};
27+
}
28+
});

src/Components/Web.JS/tsconfig.json

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
{
2+
"extends": "../Shared.JS/tsconfig.json",
23
"compilerOptions": {
3-
"moduleResolution": "node",
44
"noImplicitAny": false,
55
"noEmitOnError": true,
66
"removeComments": false,
7-
"target": "es2020",
8-
"module": "es2020",
9-
"lib": ["es2020", "dom"],
10-
"strict": true,
11-
}
7+
},
128
}
Lines changed: 9 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,16 @@
11
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';
82
import { fileURLToPath } from 'url';
3+
import createBaseConfig from '../../../../Shared.JS/rollup.config.mjs';
94

105
const __filename = fileURLToPath(import.meta.url);
116
const __dirname = path.dirname(__filename);
127

13-
console.log(__dirname);
14-
15-
export default ({ environment }) => {
16-
17-
var inputOutputMap = {
8+
export default createBaseConfig({
9+
inputOutputMap: {
1810
'AuthenticationService': './AuthenticationService.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: 'iife',
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-
};
11+
},
12+
dir: __dirname,
13+
updateConfig: (config, environment, _, input) => {
14+
config.output.format = 'iife';
15+
}
16+
});
Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
11
{
2-
"compilerOptions": {
3-
"target": "ES2022",
4-
"module": "ESNext",
5-
"lib": [ "DOM", "ES2022" ],
6-
"strict": true,
7-
"forceConsistentCasingInFileNames": true
8-
}
2+
"extends": "../../../../Shared.JS/tsconfig.json"
93
}

0 commit comments

Comments
 (0)