@@ -29,12 +29,14 @@ export interface PfeEsbuildOptions {
2929 workspace ?: string ;
3030 /** production bundles are minified */
3131 mode ?: 'development' | 'production' ;
32- /** file to bundle to */
33- outfile ?: string ;
3432 /** Packages to treat as external, i.e. not to bundle */
3533 external : string [ ] ;
3634}
3735
36+ export interface PfeEsbuildSingleFileOptions {
37+ outfile ?: string ;
38+ }
39+
3840/** lit-css transform plugin to process `.scss` files on-the-fly */
3941export function transformSass ( source : string , { filePath } : LitCSSModuleMeta ) : string {
4042 const result = Sass . compileString ( source , {
@@ -55,6 +57,44 @@ const ALWAYS_EXCLUDE = [
5557 'pfe-styles' ,
5658] ;
5759
60+ const basePlugins = ( ) => [
61+ // import scss files as LitElement CSSResult objects
62+ litCssPlugin ( { filter : / .s c s s $ / , transform : transformSass } ) ,
63+ // replace `{{version}}` with each package's version
64+ packageVersion ( ) ,
65+ ] ;
66+
67+ /** Create a single-file production bundle of all element */
68+ export async function singleFileBuild ( options ?: PfeEsbuildSingleFileOptions ) {
69+ const cwd = fileURLToPath ( new URL ( '../..' , import . meta. url ) ) ;
70+ try {
71+ const result = await esbuild . build ( {
72+ absWorkingDir : cwd ,
73+ allowOverwrite : true ,
74+ bundle : true ,
75+ entryPoints : [ join ( cwd , 'docs' , 'demo' , 'bundle.ts' ) ] ,
76+ format : 'esm' ,
77+ legalComments : 'linked' ,
78+ logLevel : 'info' ,
79+ minify : true ,
80+ minifyWhitespace : true ,
81+ outfile : options ?. outfile ?? 'pfe.min.js' ,
82+ sourcemap : true ,
83+ treeShaking : true ,
84+ watch : false ,
85+ plugins : [
86+ ...basePlugins ( ) ,
87+ ] ,
88+ } ) ;
89+ console . log ( result ) ;
90+ result . stop ?.( ) ;
91+ return result . outputFiles ?. map ( x => x . path ) ?? [ ] ;
92+ } catch ( error ) {
93+ console . log ( error ) ;
94+ process . exit ( 1 ) ;
95+ }
96+ }
97+
5898/**
5999 * Build all components in a monorepo
60100 */
@@ -111,11 +151,7 @@ export async function pfeBuild(options?: PfeEsbuildOptions) {
111151 minify : mode === 'production' ,
112152 minifyWhitespace : mode === 'production' ,
113153
114- ...options ?. outfile ? {
115- outfile : options . outfile
116- } : {
117- outdir : workspace ,
118- } ,
154+ outdir : workspace ,
119155
120156 external : [
121157 ...options ?. bundle ? [ ] : [
@@ -127,10 +163,7 @@ export async function pfeBuild(options?: PfeEsbuildOptions) {
127163 ] ,
128164
129165 plugins : [
130- // import scss files as LitElement CSSResult objects
131- litCssPlugin ( { filter : / .s c s s $ / , transform : transformSass } ) ,
132- // replace `{{version}}` with each package's version
133- packageVersion ( ) ,
166+ ...basePlugins ( ) ,
134167 // ignore sub components bundling like "pfe-progress-steps-item"
135168 externalSubComponents ( ) ,
136169 // don't bundle node_module dependencies
0 commit comments