tsbundle/ts/index.ts

87 lines
2.2 KiB
TypeScript
Raw Normal View History

2019-05-06 12:00:21 +00:00
import * as early from '@pushrocks/early';
early.start('tsbundle');
2019-04-20 17:59:33 +00:00
import * as plugins from './tsbundle.plugins';
2019-05-08 09:05:13 +00:00
import { logger } from './tsbundle.logging';
2019-05-06 12:00:21 +00:00
early.stop();
2019-04-20 17:59:33 +00:00
2019-04-30 10:49:10 +00:00
const rollupOptions: plugins.rollup.RollupOptions = {
input: `ts_web/index.ts`,
output: {
name: 'tsbundle',
// file: 'dist_web/bundle.js',
file: 'dist_web/bundle.js',
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({
useTsconfigDeclarationDir: true,
tsconfigOverride: {
compilerOptions: {
declaration: true,
emitDecoratorMetadata: true,
experimentalDecorators: true,
inlineSourceMap: true,
noEmitOnError: true,
2019-04-30 11:50:19 +00:00
lib: ['es2017', 'dom'],
target: 'es2017',
2019-04-30 10:49:10 +00:00
noImplicitAny: false
}
}
}),
// 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
plugins.rollupSourceMaps(),
plugins.rollupBabel({
2019-04-30 14:08:09 +00:00
runtimeHelpers: true,
2019-04-30 10:49:10 +00:00
extensions: ['.js', '.jsx', '.ts', '.tsx'],
babelrc: false,
2019-04-30 14:00:38 +00:00
presets: [
[
'@babel/preset-env',
{
modules: false,
targets: {
chrome: '41'
}
}
]
2019-04-30 14:08:09 +00:00
],
plugins: [
[
'@babel/plugin-transform-runtime',
{
regenerator: true
}
]
2019-04-30 14:00:38 +00:00
]
2019-04-30 10:49:10 +00:00
})
]
};
async function build() {
// create a bundle
2019-05-06 12:00:21 +00:00
logger.log('info', `starting bundling now!`);
2019-04-30 10:49:10 +00:00
const bundle = await plugins.rollup.rollup(rollupOptions);
bundle.generate(rollupOptions.output);
bundle.write(rollupOptions.output);
2019-05-06 12:00:21 +00:00
logger.log('ok', `Successfully bundled files!`);
2019-04-30 10:49:10 +00:00
}
build();