-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6aa4d09
commit 35c63da
Showing
4 changed files
with
45 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,76 +1,50 @@ | ||
const esbuild = require('esbuild'); | ||
const glob = require('glob'); | ||
|
||
const buildTypes = { | ||
cjs: { | ||
splitting: false, | ||
format: 'cjs', | ||
tsconfig: './tsconfig.json', | ||
destination: '/cjs' | ||
}, | ||
esm: { | ||
splitting: true, | ||
format: 'esm', | ||
tsconfig: './tsconfig.esm.json', | ||
destination: '' | ||
} | ||
}; | ||
/* | ||
The reason why we use esbuild instead of tsc is because esbuild can output .mjs files | ||
*/ | ||
|
||
function esbuildWrapper( | ||
buildType = 'esm', | ||
options = { | ||
outDir: 'out' | ||
} | ||
) { | ||
const { format, splitting, tsconfig, destination } = buildTypes[buildType]; | ||
const filesToInclude = ['./src/**/*.ts'].join(','); | ||
|
||
const filesToInclude = [ | ||
// './src/**/*.tsx', | ||
'./src/**/*.ts' | ||
// './src/**/*.scss', | ||
].join(','); | ||
const allFiles = glob.sync(filesToInclude); | ||
|
||
return function executeBuildCommand() { | ||
const allFiles = glob.sync(filesToInclude); | ||
const files = allFiles.filter((file) => { | ||
const hasTestFiles = file.includes('/tests/') || file.includes('/stories/'); | ||
return !hasTestFiles; | ||
}); | ||
|
||
const files = allFiles.filter((file) => { | ||
const hasTestFiles = | ||
file.includes('/tests/') || file.includes('/stories/'); | ||
return !hasTestFiles; | ||
const executeBuild = () => | ||
esbuild | ||
.build({ | ||
entryPoints: files, | ||
splitting: true, | ||
format: 'esm', | ||
outdir: 'out', | ||
treeShaking: true, | ||
minify: true, | ||
bundle: true, | ||
sourcemap: true, | ||
chunkNames: '__chunks__/[name]-[hash]', | ||
target: ['es2021'], | ||
outExtension: { '.js': '.mjs' }, | ||
tsconfig: './tsconfig.json', | ||
platform: 'node', | ||
define: { | ||
global: 'global', | ||
process: 'process', | ||
Buffer: 'Buffer' | ||
} | ||
}) | ||
.then(() => { | ||
console.log( | ||
'\x1b[36m%s\x1b[0m', | ||
`[${new Date().toLocaleTimeString()}] sdk-dapp-core build succeeded for esm types` | ||
); | ||
}) | ||
.catch((err) => { | ||
console.log(11, err); | ||
process.exit(1); | ||
}); | ||
|
||
esbuild | ||
.build({ | ||
entryPoints: files, | ||
splitting, | ||
format, | ||
outdir: `${options.outDir}${destination}`, | ||
treeShaking: true, | ||
minify: true, | ||
bundle: true, | ||
sourcemap: true, | ||
chunkNames: '__chunks__/[name]-[hash]', | ||
target: ['es2021'], | ||
outExtension: { '.js': '.mjs' }, | ||
tsconfig, | ||
platform: 'node', | ||
define: { | ||
global: 'global', | ||
process: 'process', | ||
Buffer: 'Buffer', | ||
'process.env.NODE_ENV': `"production"` | ||
} | ||
}) | ||
.then(() => { | ||
console.log( | ||
'\x1b[36m%s\x1b[0m', | ||
`[${new Date().toLocaleTimeString()}] sdk-dapp build succeeded for ${format} types` | ||
); | ||
}) | ||
.catch(() => process.exit(1)); | ||
}; | ||
} | ||
|
||
esbuildWrapper('esm')(); | ||
// cjs will be performed by tsc | ||
// esbuildWrapper('cjs')(); | ||
executeBuild(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,5 @@ | |
"extends": "./tsconfig.base.json", | ||
"compilerOptions": { | ||
"module": "CommonJS", | ||
"outDir": "./out", | ||
} | ||
} |