|
1 | 1 | // Import External Dependencies |
2 | 2 | const merge = require('webpack-merge'); |
3 | | -const SSGPlugin = require('static-site-generator-webpack-plugin'); |
4 | | -const RedirectWebpackPlugin = require('redirect-webpack-plugin'); |
5 | | -const CopyWebpackPlugin = require('copy-webpack-plugin'); |
6 | | -const flattenContentTree = require('./src/utilities/flatten-content-tree'); |
7 | | -const contentTree = require('./src/_content.json'); |
8 | 3 | const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin'); |
9 | 4 | const TerserJSPlugin = require('terser-webpack-plugin'); |
| 5 | +const OfflinePlugin = require('offline-plugin'); |
10 | 6 |
|
11 | 7 | // Load Common Configuration |
12 | 8 | const common = require('./webpack.common.js'); |
13 | 9 |
|
14 | | -// content tree to path array |
15 | | -const paths = [ |
16 | | - ...flattenContentTree(contentTree), |
17 | | - '/vote', |
18 | | - '/organization', |
19 | | - '/starter-kits' |
20 | | -]; |
| 10 | +// find css files for sw |
| 11 | +const cssFiles = require('./src/utilities/find-files-in-dist')('.css'); |
| 12 | +// find favicons |
| 13 | +const favicons = require('./src/utilities/find-files-in-dist')('.ico'); |
21 | 14 |
|
22 | | -// Prod only config |
23 | | -const prod = { |
| 15 | +// fall back all urls to app shell |
| 16 | + |
| 17 | +module.exports = env => merge(common(env), { |
24 | 18 | mode: 'production', |
| 19 | + target: 'web', |
25 | 20 | optimization: { |
26 | 21 | minimizer: [ |
27 | 22 | new TerserJSPlugin({}), |
28 | 23 | new OptimizeCSSAssetsPlugin({}) |
29 | 24 | ] |
30 | 25 | }, |
31 | 26 | plugins: [ |
32 | | - new CopyWebpackPlugin([ |
33 | | - { |
34 | | - from: './assets/PWA', |
35 | | - to: './' |
36 | | - }, |
37 | | - { |
38 | | - from: './assets/icon-square-small-slack.png', |
39 | | - to: './assets/' |
40 | | - }, |
41 | | - { |
42 | | - from: './assets/icon-square-big.svg', |
43 | | - to: './assets/' |
44 | | - }, |
45 | | - 'CNAME' |
46 | | - ]) |
| 27 | + new OfflinePlugin({ |
| 28 | + autoUpdate: true, |
| 29 | + publicPath: '/', |
| 30 | + appShell: '/app-shell/', |
| 31 | + // make sure to cache homepage and app shell as app shell for the rest of the pages. |
| 32 | + externals: ['/app-shell/', '/', '/manifest.json', ...cssFiles, ...favicons], |
| 33 | + excludes: [], |
| 34 | + AppCache: { |
| 35 | + publicPath: '/' |
| 36 | + } |
| 37 | + }) |
47 | 38 | ] |
48 | | -}; |
49 | | - |
50 | | -// Export both SSG and SPA configurations |
51 | | -module.exports = env => [ |
52 | | - merge(common(env), prod, { |
53 | | - target: 'node', |
54 | | - entry: { |
55 | | - index: './server.jsx' |
56 | | - }, |
57 | | - plugins: [ |
58 | | - new SSGPlugin({ |
59 | | - globals: { |
60 | | - window: {} |
61 | | - }, |
62 | | - paths, |
63 | | - locals: { |
64 | | - content: contentTree |
65 | | - } |
66 | | - }), |
67 | | - new RedirectWebpackPlugin({ |
68 | | - redirects: { |
69 | | - 'support': '/contribute/', |
70 | | - 'writers-guide': '/contribute/writers-guide/', |
71 | | - 'get-started': '/guides/getting-started/', |
72 | | - 'get-started/install-webpack': '/guides/installation/', |
73 | | - 'get-started/why-webpack': '/guides/why-webpack/', |
74 | | - 'pluginsapi': '/api/plugins/', |
75 | | - 'pluginsapi/compiler': '/api/compiler-hooks/', |
76 | | - 'pluginsapi/template': '/api/template/', |
77 | | - 'api/passing-a-config': '/configuration/configuration-types/', |
78 | | - 'api/plugins/compiler': '/api/compiler-hooks/', |
79 | | - 'api/plugins/compilation': '/api/compilation/', |
80 | | - 'api/plugins/module-factories': '/api/module-methods/', |
81 | | - 'api/plugins/parser': '/api/parser/', |
82 | | - 'api/plugins/tapable': '/api/tapable/', |
83 | | - 'api/plugins/template': '/api/template/', |
84 | | - 'api/plugins/resolver': '/api/resolver/', |
85 | | - 'development': '/contribute/', |
86 | | - 'development/plugin-patterns': '/contribute/plugin-patterns/', |
87 | | - 'development/release-process': '/contribute/release-process/', |
88 | | - 'development/how-to-write-a-loader': '/contribute/writing-a-loader/', |
89 | | - 'development/how-to-write-a-plugin': '/contribute/writing-a-plugin/', |
90 | | - 'guides/code-splitting-import': '/guides/code-splitting/', |
91 | | - 'guides/code-splitting-require': '/guides/code-splitting/', |
92 | | - 'guides/code-splitting-async': '/guides/code-splitting/', |
93 | | - 'guides/code-splitting-css': '/guides/code-splitting/', |
94 | | - 'guides/code-splitting-libraries': '/guides/code-splitting/', |
95 | | - 'guides/why-webpack': '/comparison/', |
96 | | - 'guides/production-build': '/guides/production/', |
97 | | - 'migrating': '/migrate/3/', |
98 | | - 'plugins/no-emit-on-errors-plugin': '/configuration/optimization/#optimization-noemitonerrors', |
99 | | - 'concepts/mode': '/configuration/mode' |
100 | | - } |
101 | | - }) |
102 | | - ], |
103 | | - output: { |
104 | | - filename: 'server.[name].js', |
105 | | - libraryTarget: 'umd' |
106 | | - } |
107 | | - }), |
108 | | - merge(common(env), prod, { |
109 | | - target: 'web' |
110 | | - }) |
111 | | -]; |
| 39 | +}); |
0 commit comments