@@ -4,58 +4,104 @@ const merge = require("webpack-merge");
44const MiniCssExtractPlugin = require ( "mini-css-extract-plugin" ) ;
55const PreloadWebpackPlugin = require ( "preload-webpack-plugin" ) ;
66const HtmlWebpackPlugin = require ( "html-webpack-plugin" ) ;
7+ const WebpackPwaManifest = require ( "webpack-pwa-manifest" ) ;
8+ const { GenerateSW } = require ( "workbox-webpack-plugin" ) ;
9+
710// const { BundleAnalyzerPlugin } = require("webpack-bundle-analyzer");
811
912const root = path . join ( __dirname , ".." ) ;
1013const prod = process . env . NODE_ENV === "production" || process . env . CI === "true" ;
1114
1215module . exports = ( options = { } ) => merge (
13- require ( "./webpack.general.config" ) ( options ) , {
14- devtool : prod ? "none" : "cheap-module-eval-source-map" ,
15- mode : prod ? "production" : "development" ,
16- entry : prod ? options . entry : [
17- "webpack-hot-middleware/client?reload=true&quiet=true" ,
18- options . entry ,
19- ] ,
20- module : {
21- rules : [ {
22- test : / \. s ? c s s $ / ,
23- // This is required otherwise it'll fail to resolve CSS in common.
24- include : root ,
25- use : [ {
26- loader : MiniCssExtractPlugin . loader ,
27- } , {
28- loader : "css-loader" ,
29- } , {
30- loader : "sass-loader" ,
31- } ] ,
32- } , {
33- test : / \. ( p n g | t t f | w o f f | e o t | w o f f 2 ) $ / ,
34- use : [ {
35- loader : "file-loader" ,
36- options : {
37- name : "[path][name].[ext]" ,
38- } ,
39- } ] ,
40- } , {
41- test : / \. s v g $ / ,
42- loader : 'url-loader'
43- } ] ,
44- } ,
45- plugins : [
46- new MiniCssExtractPlugin ( {
47- filename : "[name].css" ,
48- chunkFilename : "[id].css" ,
49- } ) ,
50- new HtmlWebpackPlugin ( {
51- template : options . template ,
52- } ) ,
53- new PreloadWebpackPlugin ( {
54- rel : "preload" ,
55- as : "script" ,
56- } ) ,
57- ] . concat ( prod ? [ ] : [
58- new webpack . HotModuleReplacementPlugin ( ) ,
59- ] ) ,
60- target : "web" ,
61- } ) ;
16+ require ( "./webpack.general.config" ) ( options ) , {
17+ devtool : prod ? "none" : "cheap-module-eval-source-map" ,
18+ mode : prod ? "production" : "development" ,
19+ entry : prod ? options . entry : [
20+ "webpack-hot-middleware/client?reload=true&quiet=true" ,
21+ options . entry ,
22+ ] ,
23+ module : {
24+ rules : [ {
25+ test : / \. s ? c s s $ / ,
26+ // This is required otherwise it'll fail to resolve CSS in common.
27+ include : root ,
28+ use : [ {
29+ loader : MiniCssExtractPlugin . loader ,
30+ } , {
31+ loader : "css-loader" ,
32+ } , {
33+ loader : "sass-loader" ,
34+ } ] ,
35+ } , {
36+ test : / \. ( p n g | t t f | w o f f | e o t | w o f f 2 ) $ / ,
37+ use : [ {
38+ loader : "file-loader" ,
39+ options : {
40+ name : "[path][name].[ext]" ,
41+ } ,
42+ } ] ,
43+ } , {
44+ test : / \. s v g $ / ,
45+ loader : 'url-loader'
46+ } ] ,
47+ } ,
48+ plugins : [
49+ new MiniCssExtractPlugin ( {
50+ filename : "[name].css" ,
51+ chunkFilename : "[id].css"
52+ } ) ,
53+ new HtmlWebpackPlugin ( {
54+ template : options . template
55+ } ) ,
56+ new PreloadWebpackPlugin ( {
57+ rel : "preload" ,
58+ as : "script"
59+ } ) ,
60+ new WebpackPwaManifest ( {
61+ name : "Coder" ,
62+ short_name : "Coder" ,
63+ description : "Run VS Code on a remote server" ,
64+ background_color : "#e5e5e5" ,
65+ icons : [
66+ {
67+ src : path . join ( root , "packages/web/assets/logo.png" ) ,
68+ sizes : [ 96 , 128 , 192 , 256 , 384 ]
69+ }
70+ ]
71+ } )
72+ ] . concat ( prod ? [
73+ new GenerateSW ( {
74+ runtimeCaching : [
75+ {
76+ urlPattern : new RegExp ( ".*" ) ,
77+ handler : "StaleWhileRevalidate" ,
78+ options : {
79+ cacheName : "code-server" ,
80+ expiration : {
81+ maxAgeSeconds : 86400
82+ } ,
83+ cacheableResponse : {
84+ statuses : [ 0 , 200 ]
85+ }
86+ }
87+ }
88+ // Network first caching is also possible.
89+ /*{
90+ urlPattern: "",
91+ handler: "NetworkFirst",
92+ options: {
93+ networkTimeoutSeconds: 4,
94+ cacheName: "code-server",
95+ expiration: {
96+ maxAgeSeconds: 86400,
97+ },
98+ cacheableResponse: {
99+ statuses: [0, 200],
100+ },
101+ },
102+ }*/
103+ ]
104+ } )
105+ ] : [ new webpack . HotModuleReplacementPlugin ( ) ] ) ,
106+ target : "web"
107+ } ) ;
0 commit comments