@@ -94,6 +94,94 @@ const electronPreloadConfig = (/*env, argv*/) => {
9494 return merge ( tsConfig , config ) ;
9595} ;
9696
97+ const libConfig = ( env , argv ) => {
98+ /** @type {import('webpack').Configuration['entry'] } */
99+ const entry = {
100+ index : "./src/index.ts" ,
101+ } ;
102+
103+ const extraPlugins = [ ] ;
104+
105+ const patterns = [
106+ { from : "node_modules/@webrecorder/wabac/dist/sw.js" , to : "sw.js" } ,
107+ ] ;
108+ extraPlugins . push ( new CopyPlugin ( { patterns } ) ) ;
109+
110+ /** @type {import('webpack').Configuration } */
111+ const config = {
112+ target : "web" ,
113+ mode : "production" ,
114+ cache : {
115+ type : isDevServer ? "memory" : "filesystem" ,
116+ } ,
117+ resolve : {
118+ fallback : { crypto : false } ,
119+ } ,
120+ entry,
121+ optimization,
122+ output : {
123+ path : path . join ( __dirname , "dist" ) ,
124+ filename : "[name].js" ,
125+ globalObject : "self" ,
126+ library : {
127+ type : "module" ,
128+ } ,
129+ publicPath : "/" ,
130+ } ,
131+ experiments : {
132+ outputModule : true ,
133+ } ,
134+
135+ devtool : argv . mode === "production" ? undefined : "source-map" ,
136+
137+ plugins : [
138+ new webpack . NormalModuleReplacementPlugin ( / ^ n o d e : * / , ( resource ) => {
139+ switch ( resource . request ) {
140+ case "node:stream" :
141+ resource . request = "stream-browserify" ;
142+ break ;
143+ }
144+ } ) ,
145+
146+ new webpack . optimize . LimitChunkCountPlugin ( {
147+ maxChunks : 1 ,
148+ } ) ,
149+ new webpack . ProvidePlugin ( {
150+ process : "process/browser" ,
151+ } ) ,
152+ new MiniCssExtractPlugin ( ) ,
153+ new webpack . DefinePlugin ( {
154+ __SW_NAME__ : JSON . stringify ( "sw.js" ) ,
155+ __HELPER_PROXY__ : JSON . stringify ( HELPER_PROXY ) ,
156+ __GDRIVE_CLIENT_ID__ : JSON . stringify ( GDRIVE_CLIENT_ID ) ,
157+ __VERSION__ : JSON . stringify ( package_json . version ) ,
158+ } ) ,
159+ new webpack . BannerPlugin ( BANNER_TEXT ) ,
160+ ...extraPlugins ,
161+ ] ,
162+
163+ module : {
164+ rules : [
165+ {
166+ test : / \. s v g $ / ,
167+ use : [ "raw-loader" ] ,
168+ } ,
169+ {
170+ test : / m a i n .s c s s $ / ,
171+ use : [ "css-loader" , "sass-loader" ] ,
172+ } ,
173+ {
174+ test : / w o m b a t .j s | w o m b a t W o r k e r s .j s | i n d e x .h t m l $ / i,
175+ use : [ "raw-loader" ] ,
176+ } ,
177+ ] ,
178+ } ,
179+ } ;
180+ return merge ( tsConfig , config ) ;
181+ } ;
182+
183+
184+
97185const browserConfig = ( env , argv ) => {
98186 const isDevServer = process . env . WEBPACK_SERVE ;
99187
@@ -125,19 +213,13 @@ const browserConfig = (env, argv) => {
125213 } ,
126214 entry,
127215 optimization,
128- devtool : argv . mode === "production" ? undefined : "source-map" ,
129216 output : {
130217 path : path . join ( __dirname ) ,
131218 filename : "[name].js" ,
132- library : {
133- type : "module" ,
134- } ,
219+ libraryTarget : "self" ,
135220 globalObject : "self" ,
136221 publicPath : "/" ,
137222 } ,
138- experiments : {
139- outputModule : true ,
140- } ,
141223 devServer : {
142224 compress : true ,
143225 port : 9990 ,
0 commit comments