2019-06-16 15:02:38 +00:00
|
|
|
import * as plugins from './tsbundle.plugins';
|
|
|
|
import { logger } from './tsbundle.logging';
|
|
|
|
|
|
|
|
export class TsBundle {
|
|
|
|
/**
|
|
|
|
* the basic default options for rollup
|
|
|
|
*/
|
2020-03-14 22:41:25 +00:00
|
|
|
public getBaseOptions(
|
|
|
|
fromArg: string = `ts_web/index.ts`,
|
|
|
|
toArg: string = 'dist_bundle/bundle.js'
|
|
|
|
) {
|
2019-07-19 08:52:27 +00:00
|
|
|
logger.log('info', `from: ${fromArg}`);
|
|
|
|
logger.log('info', `to: ${toArg}`);
|
|
|
|
|
2019-06-16 15:02:38 +00:00
|
|
|
const baseOptions: plugins.rollup.RollupOptions = {
|
2019-07-18 16:15:24 +00:00
|
|
|
input: fromArg,
|
2019-06-16 15:02:38 +00:00
|
|
|
output: {
|
|
|
|
name: 'tsbundle',
|
2019-07-18 16:15:24 +00:00
|
|
|
file: toArg,
|
2019-06-16 15:02:38 +00:00
|
|
|
format: 'iife',
|
|
|
|
sourcemap: true
|
|
|
|
},
|
|
|
|
// Indicate here external modules you don't wanna include in your bundle (i.e.: 'lodash')
|
|
|
|
external: [],
|
|
|
|
watch: {
|
|
|
|
include: ['src/**']
|
|
|
|
},
|
|
|
|
plugins: [
|
|
|
|
// Compile TypeScript files
|
|
|
|
plugins.rollupTypescript({
|
2020-03-20 06:01:41 +00:00
|
|
|
include: plugins.path.parse(fromArg).dir ? plugins.path.parse(fromArg).dir + '/**/*.ts' : '**/*.ts',
|
2020-03-13 14:53:15 +00:00
|
|
|
declaration: false,
|
|
|
|
emitDecoratorMetadata: true,
|
|
|
|
experimentalDecorators: true,
|
|
|
|
inlineSourceMap: true,
|
|
|
|
noEmitOnError: true,
|
2020-03-18 16:32:33 +00:00
|
|
|
lib: ['esnext', 'dom', 'es2017.object'],
|
2020-03-13 14:53:15 +00:00
|
|
|
noImplicitAny: false,
|
2020-05-25 16:43:58 +00:00
|
|
|
target: 'es2018',
|
|
|
|
allowSyntheticDefaultImports: true
|
2019-06-16 15:02:38 +00:00
|
|
|
}),
|
|
|
|
// Allow node_modules resolution, so you can use 'external' to control
|
|
|
|
// which external modules to include in the bundle
|
|
|
|
// https://github.com/rollup/rollup-plugin-node-resolve#usage
|
|
|
|
plugins.rollupResolve(),
|
|
|
|
plugins.rollupCommonjs({
|
|
|
|
namedExports: {
|
|
|
|
'node_modules/@pushrocks/smartstate/dist/index.js': ['Smartstate']
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
|
|
|
|
// Resolve source maps to the original source
|
2019-08-25 14:35:22 +00:00
|
|
|
plugins.rollupSourceMaps()
|
2019-07-18 16:15:24 +00:00
|
|
|
/*plugins.rollupBabel({
|
2019-06-16 15:02:38 +00:00
|
|
|
runtimeHelpers: true,
|
|
|
|
extensions: ['.js', '.jsx', '.ts', '.tsx'],
|
|
|
|
babelrc: false,
|
|
|
|
presets: [
|
|
|
|
[
|
|
|
|
'@babel/preset-env',
|
|
|
|
{
|
|
|
|
modules: false,
|
|
|
|
targets: {
|
|
|
|
chrome: '41'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
],
|
|
|
|
plugins: [
|
|
|
|
[
|
|
|
|
'@babel/plugin-transform-runtime',
|
|
|
|
{
|
|
|
|
regenerator: true
|
|
|
|
}
|
|
|
|
]
|
|
|
|
]
|
2019-07-18 16:15:24 +00:00
|
|
|
})*/
|
2019-06-16 15:02:38 +00:00
|
|
|
]
|
|
|
|
};
|
|
|
|
return baseOptions;
|
|
|
|
}
|
2019-07-18 16:15:24 +00:00
|
|
|
|
|
|
|
public getOptionsTest(fromArg: string, toArg: string): plugins.rollup.RollupOptions {
|
2019-07-19 10:09:00 +00:00
|
|
|
return this.getBaseOptions(fromArg, toArg);
|
2019-07-18 16:15:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public getOptionsProduction(fromArg: string, toArg: string): plugins.rollup.RollupOptions {
|
2019-07-19 10:09:00 +00:00
|
|
|
const productionOptions = this.getBaseOptions(fromArg, toArg);
|
2020-03-14 22:41:25 +00:00
|
|
|
productionOptions.plugins.push(
|
|
|
|
plugins.rollupTerser({
|
|
|
|
compress: true,
|
|
|
|
mangle: true,
|
|
|
|
sourcemap: true
|
|
|
|
})
|
|
|
|
);
|
2019-07-18 16:15:24 +00:00
|
|
|
return productionOptions;
|
|
|
|
}
|
|
|
|
|
2019-07-19 08:52:27 +00:00
|
|
|
constructor() {
|
|
|
|
// Nothing here
|
|
|
|
}
|
2019-07-18 16:15:24 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* creates a bundle for the test enviroment
|
|
|
|
*/
|
|
|
|
public async buildTest(fromArg: string, toArg: string) {
|
|
|
|
// create a bundle
|
|
|
|
logger.log('info', `bundling for TEST!`);
|
2019-07-19 08:52:27 +00:00
|
|
|
const buildOptions = this.getOptionsTest(fromArg, toArg);
|
|
|
|
const bundle = await plugins.rollup.rollup(buildOptions);
|
2020-03-02 09:42:44 +00:00
|
|
|
bundle.generate(buildOptions.output as plugins.rollup.OutputOptions);
|
|
|
|
await bundle.write(buildOptions.output as plugins.rollup.OutputOptions);
|
2019-07-18 16:15:24 +00:00
|
|
|
logger.log('ok', `Successfully bundled files!`);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* creates a bundle for the production environment
|
|
|
|
*/
|
|
|
|
public async buildProduction(fromArg: string, toArg: string) {
|
|
|
|
// create a bundle
|
|
|
|
logger.log('info', `bundling for PRODUCTION!`);
|
2019-07-19 08:52:27 +00:00
|
|
|
const buildOptions = this.getOptionsProduction(fromArg, toArg);
|
|
|
|
const bundle = await plugins.rollup.rollup(buildOptions);
|
2020-03-02 09:42:44 +00:00
|
|
|
bundle.generate(buildOptions.output as plugins.rollup.OutputOptions);
|
|
|
|
await bundle.write(buildOptions.output as plugins.rollup.OutputOptions);
|
2019-07-18 16:15:24 +00:00
|
|
|
logger.log('ok', `Successfully bundled files!`);
|
|
|
|
}
|
2019-06-16 15:02:38 +00:00
|
|
|
}
|