Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
d5753019cf | |||
a3ab55cbc6 | |||
ae16fd8170 | |||
cf9ca73cd8 |
4
package-lock.json
generated
4
package-lock.json
generated
@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "@gitzone/tsbundle",
|
||||
"version": "1.0.92",
|
||||
"version": "1.0.94",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@gitzone/tsbundle",
|
||||
"version": "1.0.92",
|
||||
"version": "1.0.94",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@babel/core": "^7.17.5",
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@gitzone/tsbundle",
|
||||
"version": "1.0.92",
|
||||
"version": "1.0.94",
|
||||
"private": false,
|
||||
"description": "a bundler using rollup for painless bundling of web projects",
|
||||
"main": "dist_ts/index.js",
|
||||
|
@ -9,7 +9,8 @@ tap.test('should bundle test', async () => {
|
||||
process.cwd() + '/test',
|
||||
'./ts_web/index.ts',
|
||||
'./dist_manual/test.js',
|
||||
'rollup'
|
||||
'rollup',
|
||||
{}
|
||||
);
|
||||
});
|
||||
|
||||
@ -18,7 +19,9 @@ tap.test('should bundle production', async () => {
|
||||
await tsbundleInstance.buildProduction(
|
||||
process.cwd(),
|
||||
'./test/ts_web/index.ts',
|
||||
'./test/dist_manual/production.js'
|
||||
'./test/dist_manual/production.js',
|
||||
'rollup',
|
||||
{}
|
||||
);
|
||||
});
|
||||
|
||||
|
@ -6,11 +6,15 @@ export class TsBundle {
|
||||
cwdArg: string,
|
||||
fromArg: string,
|
||||
toArg: string,
|
||||
bundlerArg: 'rollup' | 'parcel'
|
||||
bundlerArg: 'rollup' | 'parcel',
|
||||
argvArg: any
|
||||
) {
|
||||
const done = plugins.smartpromise.defer();
|
||||
const threadsimple = new plugins.smartspawn.ThreadSimple(
|
||||
plugins.path.join(plugins.smartpath.get.dirnameFromImportMetaUrl(import.meta.url), './tsbundle.class.tsbundleprocess.js'),
|
||||
plugins.path.join(
|
||||
plugins.smartpath.get.dirnameFromImportMetaUrl(import.meta.url),
|
||||
'./tsbundle.class.tsbundleprocess.js'
|
||||
),
|
||||
[],
|
||||
{
|
||||
env: {
|
||||
@ -20,6 +24,7 @@ export class TsBundle {
|
||||
tsbundleFrom: fromArg,
|
||||
tsbundleTo: toArg,
|
||||
tsbundleBundler: bundlerArg,
|
||||
tsbundleArgv: argvArg ? JSON.stringify(argvArg) : '{}',
|
||||
},
|
||||
}
|
||||
);
|
||||
@ -30,10 +35,19 @@ export class TsBundle {
|
||||
await done.promise;
|
||||
}
|
||||
|
||||
public async buildProduction(cwdArg: string, fromArg: string, toArg: string) {
|
||||
public async buildProduction(
|
||||
cwdArg: string,
|
||||
fromArg: string,
|
||||
toArg: string,
|
||||
bundlerArg: 'rollup' | 'parcel',
|
||||
argvArg: any
|
||||
) {
|
||||
const done = plugins.smartpromise.defer();
|
||||
const threadsimple = new plugins.smartspawn.ThreadSimple(
|
||||
plugins.path.join(plugins.smartpath.get.dirnameFromImportMetaUrl(import.meta.url), './tsbundle.class.tsbundleprocess.js'),
|
||||
plugins.path.join(
|
||||
plugins.smartpath.get.dirnameFromImportMetaUrl(import.meta.url),
|
||||
'./tsbundle.class.tsbundleprocess.js'
|
||||
),
|
||||
[],
|
||||
{
|
||||
env: {
|
||||
@ -42,6 +56,8 @@ export class TsBundle {
|
||||
tsbundleCwd: cwdArg,
|
||||
tsbundleFrom: fromArg,
|
||||
tsbundleTo: toArg,
|
||||
tsbundleBundler: bundlerArg,
|
||||
tsbundleArgv: argvArg ? JSON.stringify(argvArg) : '{}',
|
||||
},
|
||||
}
|
||||
);
|
||||
|
@ -7,7 +7,8 @@ export class TsBundleProcess {
|
||||
*/
|
||||
public getBaseOptions(
|
||||
fromArg: string = `ts_web/index.ts`,
|
||||
toArg: string = 'dist_bundle/bundle.js'
|
||||
toArg: string = 'dist_bundle/bundle.js',
|
||||
argvArg: any
|
||||
) {
|
||||
logger.log('info', `from: ${fromArg}`);
|
||||
logger.log('info', `to: ${toArg}`);
|
||||
@ -39,8 +40,26 @@ export class TsBundleProcess {
|
||||
lib: ['dom'],
|
||||
noImplicitAny: false,
|
||||
target: 'es2020',
|
||||
module: 'es2020',
|
||||
moduleResolution: 'node12',
|
||||
allowSyntheticDefaultImports: true,
|
||||
importsNotUsedAsValues: 'preserve',
|
||||
...(argvArg && argvArg.skiplibcheck
|
||||
? {
|
||||
skipLibCheck: true,
|
||||
}
|
||||
: {}),
|
||||
...(argvArg && argvArg.allowimplicitany
|
||||
? {
|
||||
noImplicitAny: false,
|
||||
}
|
||||
: {}),
|
||||
...(argvArg && argvArg.commonjs
|
||||
? {
|
||||
module: 'commonjs',
|
||||
moduleResolution: 'node',
|
||||
}
|
||||
: {}),
|
||||
}),
|
||||
(plugins.rollupJson as any)(),
|
||||
// Allow node_modules resolution, so you can use 'external' to control
|
||||
@ -56,12 +75,20 @@ export class TsBundleProcess {
|
||||
return baseOptions;
|
||||
}
|
||||
|
||||
public getOptionsTest(fromArg: string, toArg: string): plugins.rollup.RollupOptions {
|
||||
return this.getBaseOptions(fromArg, toArg);
|
||||
public getOptionsTest(
|
||||
fromArg: string,
|
||||
toArg: string,
|
||||
argvArg: any
|
||||
): plugins.rollup.RollupOptions {
|
||||
return this.getBaseOptions(fromArg, toArg, argvArg);
|
||||
}
|
||||
|
||||
public getOptionsProduction(fromArg: string, toArg: string): plugins.rollup.RollupOptions {
|
||||
const productionOptions = this.getBaseOptions(fromArg, toArg);
|
||||
public getOptionsProduction(
|
||||
fromArg: string,
|
||||
toArg: string,
|
||||
argvArg: any
|
||||
): plugins.rollup.RollupOptions {
|
||||
const productionOptions = this.getBaseOptions(fromArg, toArg, argvArg);
|
||||
productionOptions.plugins.push(
|
||||
plugins.rollupTerser({
|
||||
compress: true,
|
||||
@ -81,13 +108,14 @@ export class TsBundleProcess {
|
||||
public async buildTest(
|
||||
fromArg: string,
|
||||
toArg: string,
|
||||
bundlerArg: 'rollup' | 'parcel' = 'rollup'
|
||||
bundlerArg: 'rollup' | 'parcel' = 'rollup',
|
||||
argvArg: any
|
||||
) {
|
||||
// create a bundle
|
||||
switch (bundlerArg) {
|
||||
case 'rollup':
|
||||
logger.log('info', `bundling for TEST!`);
|
||||
const buildOptions = this.getOptionsTest(fromArg, toArg);
|
||||
const buildOptions = this.getOptionsTest(fromArg, toArg, argvArg);
|
||||
const bundle = await plugins.rollup.rollup(buildOptions);
|
||||
bundle.generate(buildOptions.output as plugins.rollup.OutputOptions);
|
||||
await bundle.write(buildOptions.output as plugins.rollup.OutputOptions);
|
||||
@ -107,10 +135,10 @@ export class TsBundleProcess {
|
||||
/**
|
||||
* creates a bundle for the production environment
|
||||
*/
|
||||
public async buildProduction(fromArg: string, toArg: string) {
|
||||
public async buildProduction(fromArg: string, toArg: string, argvArg: any) {
|
||||
// create a bundle
|
||||
logger.log('info', `bundling for PRODUCTION!`);
|
||||
const buildOptions = this.getOptionsProduction(fromArg, toArg);
|
||||
const buildOptions = this.getOptionsProduction(fromArg, toArg, argvArg);
|
||||
const bundle = await plugins.rollup.rollup(buildOptions);
|
||||
bundle.generate(buildOptions.output as plugins.rollup.OutputOptions);
|
||||
await bundle.write(buildOptions.output as plugins.rollup.OutputOptions);
|
||||
@ -132,10 +160,15 @@ const run = async () => {
|
||||
tsbundleProcessInstance.buildTest(
|
||||
process.env.tsbundleFrom,
|
||||
process.env.tsbundleTo,
|
||||
process.env.tsbundleBundler as 'rollup' | 'parcel'
|
||||
process.env.tsbundleBundler as 'rollup' | 'parcel',
|
||||
JSON.parse(process.env.tsbundleArgv)
|
||||
);
|
||||
} else {
|
||||
tsbundleProcessInstance.buildProduction(process.env.tsbundleFrom, process.env.tsbundleTo);
|
||||
tsbundleProcessInstance.buildProduction(
|
||||
process.env.tsbundleFrom,
|
||||
process.env.tsbundleTo,
|
||||
JSON.parse(process.env.tsbundleArgv)
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -10,12 +10,12 @@ export const runCli = async () => {
|
||||
// const htmlHandler = new HtmlHandler();
|
||||
switch (true) {
|
||||
case argvArg.production || process.env.CI:
|
||||
await tsbundle.buildProduction(process.cwd(), argvArg.from, argvArg.to);
|
||||
await tsbundle.buildProduction(process.cwd(), argvArg.from, argvArg.to, 'rollup', argvArg);
|
||||
// await htmlHandler.minifyHtml();
|
||||
break;
|
||||
case argvArg.test:
|
||||
default:
|
||||
await tsbundle.buildTest(process.cwd(), argvArg.from, argvArg.to, 'rollup');
|
||||
await tsbundle.buildTest(process.cwd(), argvArg.from, argvArg.to, 'rollup', argvArg);
|
||||
// await htmlHandler.copyHtml();
|
||||
return;
|
||||
}
|
||||
@ -29,7 +29,9 @@ export const runCli = async () => {
|
||||
await tsbundle.buildProduction(
|
||||
process.cwd(),
|
||||
'./ts_web/index.ts',
|
||||
'./dist_bundle/bundle.js'
|
||||
'./dist_bundle/bundle.js',
|
||||
'rollup',
|
||||
argvArg
|
||||
);
|
||||
// await htmlHandler.minifyHtml();
|
||||
break;
|
||||
@ -39,7 +41,8 @@ export const runCli = async () => {
|
||||
process.cwd(),
|
||||
'./ts_web/index.ts',
|
||||
'./dist_bundle/bundle.js',
|
||||
'rollup'
|
||||
'rollup',
|
||||
argvArg
|
||||
);
|
||||
// await htmlHandler.copyHtml();
|
||||
return;
|
||||
@ -51,7 +54,13 @@ export const runCli = async () => {
|
||||
// const htmlHandler = new HtmlHandler();
|
||||
switch (true) {
|
||||
case argvArg.production || process.env.CI:
|
||||
await tsbundle.buildProduction(process.cwd(), './ts/index.ts', './dist_bundle/bundle.js');
|
||||
await tsbundle.buildProduction(
|
||||
process.cwd(),
|
||||
'./ts/index.ts',
|
||||
'./dist_bundle/bundle.js',
|
||||
'rollup',
|
||||
argvArg
|
||||
);
|
||||
// await htmlHandler.minifyHtml();
|
||||
break;
|
||||
case argvArg.test:
|
||||
@ -60,7 +69,8 @@ export const runCli = async () => {
|
||||
process.cwd(),
|
||||
'./ts/index.ts',
|
||||
'./dist_bundle/bundle.js',
|
||||
'rollup'
|
||||
'rollup',
|
||||
argvArg
|
||||
);
|
||||
// await htmlHandler.copyHtml();
|
||||
return;
|
||||
@ -75,7 +85,9 @@ export const runCli = async () => {
|
||||
await tsbundle.buildProduction(
|
||||
process.cwd(),
|
||||
'./ts_web/index.ts',
|
||||
'./dist_serve/bundle.js'
|
||||
'./dist_serve/bundle.js',
|
||||
'rollup',
|
||||
argvArg
|
||||
);
|
||||
await htmlHandler.minifyHtml();
|
||||
break;
|
||||
@ -85,7 +97,8 @@ export const runCli = async () => {
|
||||
process.cwd(),
|
||||
'./ts_web/index.ts',
|
||||
'./dist_serve/bundle.js',
|
||||
'rollup'
|
||||
'rollup',
|
||||
argvArg
|
||||
);
|
||||
await htmlHandler.copyHtml();
|
||||
return;
|
||||
|
@ -4,5 +4,6 @@
|
||||
"target": "ES2020",
|
||||
"module": "ES2020",
|
||||
"moduleResolution": "node12",
|
||||
"esModuleInterop": true
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user