@@ -4,58 +4,103 @@ const merge = require("webpack-merge");
4
4
const MiniCssExtractPlugin = require ( "mini-css-extract-plugin" ) ;
5
5
const PreloadWebpackPlugin = require ( "preload-webpack-plugin" ) ;
6
6
const HtmlWebpackPlugin = require ( "html-webpack-plugin" ) ;
7
+ const WebpackPwaManifest = require ( "webpack-pwa-manifest" ) ;
8
+ const { GenerateSW } = require ( "workbox-webpack-plugin" ) ;
9
+
7
10
// const { BundleAnalyzerPlugin } = require("webpack-bundle-analyzer");
8
11
9
12
const root = path . join ( __dirname , ".." ) ;
10
13
const prod = process . env . NODE_ENV === "production" || process . env . CI === "true" ;
11
14
12
15
module . 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 : "#303030" ,
65
+ icons : [
66
+ {
67
+ src : path . resolve ( "./assets/logo.png" ) ,
68
+ sizes : [ 96 , 128 , 192 , 256 , 384 ]
69
+ }
70
+ ]
71
+ } ) ,
72
+ new GenerateSW ( {
73
+ runtimeCaching : [
74
+ {
75
+ urlPattern : new RegExp ( ".*" ) ,
76
+ handler : "StaleWhileRevalidate" ,
77
+ options : {
78
+ cacheName : "code-server" ,
79
+ expiration : {
80
+ maxAgeSeconds : 86400
81
+ } ,
82
+ cacheableResponse : {
83
+ statuses : [ 0 , 200 ]
84
+ }
85
+ }
86
+ }
87
+ // Network first caching is also possible.
88
+ /*{
89
+ urlPattern: "",
90
+ handler: "NetworkFirst",
91
+ options: {
92
+ networkTimeoutSeconds: 4,
93
+ cacheName: "code-server",
94
+ expiration: {
95
+ maxAgeSeconds: 86400,
96
+ },
97
+ cacheableResponse: {
98
+ statuses: [0, 200],
99
+ },
100
+ },
101
+ }*/
102
+ ]
103
+ } )
104
+ ] . concat ( prod ? [ ] : [ new webpack . HotModuleReplacementPlugin ( ) ] ) ,
105
+ target : "web"
106
+ } ) ;
0 commit comments