@@ -11,7 +11,8 @@ function copyResources() {
1111
1212 const resources = [
1313 './node_modules/jquery/dist/jquery.min.js' ,
14- './node_modules/jquery.json-viewer/json-viewer' ,
14+ './node_modules/jquery.json-viewer/json-viewer/jquery.json-viewer.js' ,
15+ './node_modules/jquery.json-viewer/json-viewer/jquery.json-viewer.css' ,
1516 './node_modules/ag-grid-community/dist/ag-grid-community.min.noStyle.js' ,
1617 './node_modules/ag-grid-community/styles/ag-grid.min.css' ,
1718 './node_modules/ag-grid-community/styles/ag-theme-balham.min.css'
@@ -22,18 +23,41 @@ function copyResources() {
2223 const destName = path . basename ( srcPath ) ;
2324 const destPath = path . resolve ( destDir , destName ) ;
2425 if ( fs . existsSync ( srcPath ) ) {
25- fs . cpSync ( srcPath , destPath , { recursive : true } ) ;
26+ fs . copyFileSync ( srcPath , destPath ) ;
2627 } else {
2728 console . warn ( `Warning: Resource not found: ${ srcPath } ` ) ;
2829 }
2930 }
3031 console . log ( 'Resources copied.' ) ;
3132}
3233
34+ function copyWebviewAssets ( ) {
35+ const views = [
36+ { name : 'help' , src : 'src/helpViewer/webview' } ,
37+ { name : 'httpgd' , src : 'src/plotViewer/webview' }
38+ ] ;
39+
40+ for ( const view of views ) {
41+ const srcDir = path . join ( __dirname , view . src ) ;
42+ const destDir = path . join ( __dirname , 'dist' , 'webviews' , view . name ) ;
43+ fs . mkdirSync ( destDir , { recursive : true } ) ;
44+
45+ const files = fs . readdirSync ( srcDir ) ;
46+ for ( const file of files ) {
47+ if ( ! file . endsWith ( '.ts' ) ) {
48+ fs . copyFileSync ( path . join ( srcDir , file ) , path . join ( destDir , file ) ) ;
49+ }
50+ }
51+ }
52+ console . log ( 'Webview assets copied.' ) ;
53+ }
54+
3355async function main ( ) {
3456 copyResources ( ) ;
57+ copyWebviewAssets ( ) ;
3558
36- const ctx = await esbuild . context ( {
59+ // Extension context (Node)
60+ const extensionCtx = await esbuild . context ( {
3761 entryPoints : [ './src/extension.ts' ] ,
3862 bundle : true ,
3963 format : 'cjs' ,
@@ -46,12 +70,32 @@ async function main() {
4670 logLevel : 'info' ,
4771 } ) ;
4872
73+ // Webview context (Browser)
74+ const webviewCtx = await esbuild . context ( {
75+ entryPoints : {
76+ 'help/index' : './src/helpViewer/webview/index.ts' ,
77+ 'httpgd/index' : './src/plotViewer/webview/index.ts'
78+ } ,
79+ bundle : true ,
80+ minify : production ,
81+ sourcemap : ! production ,
82+ format : 'iife' ,
83+ platform : 'browser' ,
84+ outdir : 'dist/webviews' ,
85+ logLevel : 'info' ,
86+ } ) ;
87+
4988 if ( watch ) {
50- await ctx . watch ( ) ;
89+ await Promise . all ( [
90+ extensionCtx . watch ( ) ,
91+ webviewCtx . watch ( )
92+ ] ) ;
5193 console . log ( 'Watching for changes...' ) ;
5294 } else {
53- await ctx . rebuild ( ) ;
54- await ctx . dispose ( ) ;
95+ await extensionCtx . rebuild ( ) ;
96+ await webviewCtx . rebuild ( ) ;
97+ await extensionCtx . dispose ( ) ;
98+ await webviewCtx . dispose ( ) ;
5599 }
56100}
57101
0 commit comments