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