webpack.config.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /**
  2. @license
  3. Copyright (c) 2018 The Polymer Project Authors. All rights reserved.
  4. This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
  5. The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
  6. The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
  7. Code distributed by Google as part of the polymer project is also
  8. subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
  9. */
  10. const CopyWebpackPlugin = require('copy-webpack-plugin');
  11. const HtmlWebpackPlugin = require('html-webpack-plugin');
  12. const WorkboxWebpackPlugin = require('workbox-webpack-plugin');
  13. var path = require('path');
  14. module.exports = {
  15. devServer: {
  16. historyApiFallback: true
  17. },
  18. mode: 'production',
  19. output: {
  20. filename: '[name].[chunkhash:8].js'
  21. },
  22. module: {
  23. rules: [
  24. {
  25. test: /\.js$/,
  26. use: {
  27. loader: 'babel-loader',
  28. options: {
  29. presets: [
  30. ['@babel/preset-env', {targets: {ie: '11'}}]
  31. ],
  32. plugins: ['@babel/plugin-syntax-dynamic-import']
  33. }
  34. }
  35. }
  36. ]
  37. },
  38. resolve: {
  39. alias: {
  40. "react-native": "react-native-web"
  41. }
  42. },
  43. plugins: [
  44. new CopyWebpackPlugin([
  45. { from: 'images', to: 'images' },
  46. { from: 'data', to: 'data' },
  47. { from: 'node_modules/@webcomponents/webcomponentsjs', to: 'node_modules/@webcomponents/webcomponentsjs' },
  48. { from: 'manifest.json', to: 'manifest.json' },
  49. ]),
  50. new HtmlWebpackPlugin({
  51. chunksSortMode: 'none',
  52. template: 'index.html',
  53. }),
  54. new WorkboxWebpackPlugin.GenerateSW({
  55. include: ['index.html', 'manifest.json', /\.js$/],
  56. exclude: [/\/@webcomponents\/webcomponentsjs\//],
  57. navigateFallback: 'index.html',
  58. swDest: 'service-worker.js',
  59. clientsClaim: true,
  60. skipWaiting: true,
  61. runtimeCaching: [
  62. {
  63. urlPattern: /\/@webcomponents\/webcomponentsjs\//,
  64. handler: 'staleWhileRevalidate'
  65. },
  66. {
  67. urlPattern: /\/data\//,
  68. handler: 'staleWhileRevalidate'
  69. },
  70. {
  71. urlPattern: /\/images\//,
  72. handler: 'staleWhileRevalidate'
  73. },
  74. ]
  75. })
  76. ]
  77. };