1 | import * as plugins from './tsbundle.plugins';
|
2 | import { logger } from './tsbundle.logging';
|
3 |
|
4 | export class TsBundle {
|
5 | |
6 |
|
7 |
|
8 | public getBaseOptions(fromArg: string = `ts_web/index.ts`, toArg: string = 'dist_web/bundle.js') {
|
9 | logger.log('info', `from: ${fromArg}`);
|
10 | logger.log('info', `to: ${toArg}`);
|
11 |
|
12 | const baseOptions: plugins.rollup.RollupOptions = {
|
13 | input: fromArg,
|
14 | output: {
|
15 | name: 'tsbundle',
|
16 | file: toArg,
|
17 | format: 'iife',
|
18 | sourcemap: true
|
19 | },
|
20 |
|
21 | external: [],
|
22 | watch: {
|
23 | include: ['src/**']
|
24 | },
|
25 | plugins: [
|
26 |
|
27 | plugins.rollupTypescript({
|
28 | useTsconfigDeclarationDir: true,
|
29 | tsconfigOverride: {
|
30 | compilerOptions: {
|
31 | declaration: true,
|
32 | emitDecoratorMetadata: true,
|
33 | experimentalDecorators: true,
|
34 | inlineSourceMap: true,
|
35 | noEmitOnError: true,
|
36 | lib: ['esnext', 'dom'],
|
37 | target: 'es2018',
|
38 | noImplicitAny: false
|
39 | }
|
40 | }
|
41 | }),
|
42 |
|
43 |
|
44 |
|
45 | plugins.rollupResolve(),
|
46 | plugins.rollupCommonjs({
|
47 | namedExports: {
|
48 | 'node_modules/@pushrocks/smartstate/dist/index.js': ['Smartstate']
|
49 | }
|
50 | }),
|
51 |
|
52 |
|
53 | plugins.rollupSourceMaps()
|
54 | |
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 |
|
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 |
|
73 |
|
74 |
|
75 |
|
76 |
|
77 |
|
78 | ]
|
79 | };
|
80 | return baseOptions;
|
81 | }
|
82 |
|
83 | public getOptionsTest(fromArg: string, toArg: string): plugins.rollup.RollupOptions {
|
84 | return this.getBaseOptions(fromArg, toArg);
|
85 | }
|
86 |
|
87 | public getOptionsProduction(fromArg: string, toArg: string): plugins.rollup.RollupOptions {
|
88 | const productionOptions = this.getBaseOptions(fromArg, toArg);
|
89 | productionOptions.plugins.push(plugins.rollupTerser({
|
90 | compress: true,
|
91 | mangle: true,
|
92 | sourcemap: true
|
93 | }));
|
94 | return productionOptions;
|
95 | }
|
96 |
|
97 | constructor() {
|
98 |
|
99 | }
|
100 |
|
101 | |
102 |
|
103 |
|
104 | public async buildTest(fromArg: string, toArg: string) {
|
105 |
|
106 | logger.log('info', `bundling for TEST!`);
|
107 | const buildOptions = this.getOptionsTest(fromArg, toArg);
|
108 | const bundle = await plugins.rollup.rollup(buildOptions);
|
109 | bundle.generate(buildOptions.output as plugins.rollup.OutputOptions);
|
110 | await bundle.write(buildOptions.output as plugins.rollup.OutputOptions);
|
111 | logger.log('ok', `Successfully bundled files!`);
|
112 | }
|
113 |
|
114 | |
115 |
|
116 |
|
117 | public async buildProduction(fromArg: string, toArg: string) {
|
118 |
|
119 | logger.log('info', `bundling for PRODUCTION!`);
|
120 | const buildOptions = this.getOptionsProduction(fromArg, toArg);
|
121 | const bundle = await plugins.rollup.rollup(buildOptions);
|
122 | bundle.generate(buildOptions.output as plugins.rollup.OutputOptions);
|
123 | await bundle.write(buildOptions.output as plugins.rollup.OutputOptions);
|
124 | logger.log('ok', `Successfully bundled files!`);
|
125 | }
|
126 | }
|