Advertisement
Guest User

Untitled

a guest
Apr 25th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.44 KB | None | 0 0
  1. const path = require('path');
  2.  
  3. /* Webpack's plugins */
  4. const DefinePlugin = require('webpack/lib/DefinePlugin');
  5. const HashedModuleIdsPlugin = require('webpack/lib/HashedModuleIdsPlugin');
  6. const NamedModulesPlugin = require('webpack/lib/NamedModulesPlugin');
  7. const OccurrenceOrderPlugin = require('webpack/lib/optimize/OccurrenceOrderPlugin');
  8. const ProvidePlugin = require('webpack/lib/ProvidePlugin');
  9. const HotModuleReplacementPlugin = require('webpack/lib/HotModuleReplacementPlugin');
  10.  
  11. /* Third party plugins */
  12. const CleanWebpackPlugin = require('clean-webpack-plugin');
  13. const CopyWebpackPlugin = require('copy-webpack-plugin');
  14. const ErrorOverlayPlugin = require('error-overlay-webpack-plugin');
  15. const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
  16. const HtmlWebpackPlugin = require('html-webpack-plugin');
  17. const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
  18. const ManifestPlugin = require('webpack-manifest-plugin');
  19.  
  20. const ENVIRONMENT = require('./environment.config');
  21.  
  22. const { NODE_ENV, PORT } = ENVIRONMENT;
  23. const DEVELOPMENT = NODE_ENV === 'development';
  24. const SRC_PATH = path.resolve(__dirname, 'src');
  25.  
  26. module.exports = {
  27. mode: NODE_ENV,
  28. entry: { main: './src/app/index.tsx' },
  29. output: {
  30. path: path.resolve(__dirname, 'dist'),
  31. filename: 'assets/js/[name].[hash].js',
  32. chunkFilename: 'assets/js/[name].[chunkhash].js',
  33. publicPath: '/',
  34. jsonpFunction: 'n',
  35. },
  36. resolve: {
  37. extensions: ['.ts', '.tsx', '.js', '.json'],
  38. modules: ['node_modules'],
  39. alias: {
  40. '@': path.resolve(SRC_PATH),
  41. },
  42. },
  43. devtool: NODE_ENV !== 'production' ? 'cheap-module-source-map' : '',
  44. module: {
  45. rules: [
  46. {
  47. test: /\.tsx?$/,
  48. loader: 'babel-loader',
  49. include: path.resolve(SRC_PATH, 'app'),
  50. exclude: [/[/\\\\]node_modules[/\\\\]/],
  51. },
  52. {
  53. test: /\.css$/,
  54. loaders: ['style-loader', 'css-loader'],
  55. },
  56. {
  57. test: /\.(png|jpe?g|gif|svg)$/i,
  58. loader: 'url-loader',
  59. options: {
  60. limit: 10000,
  61. name: 'assets/images/[name].[hash:8].[ext]',
  62. },
  63. },
  64. {
  65. test: /\.woff(\?v=\d+\.\d+\.\d+)?$/,
  66. use: 'url-loader?limit=10000&mimetype=application/font-woff',
  67. },
  68. {
  69. test: /\.woff2(\?v=\d+\.\d+\.\d+)?$/,
  70. use: 'url-loader?limit=10000&mimetype=application/font-woff',
  71. },
  72. {
  73. test: /\.ttf(\?v=\d+\.\d+\.\d+)?$/,
  74. use: 'url-loader?limit=10000&mimetype=application/octet-stream',
  75. },
  76. {
  77. test: /\.eot(\?v=\d+\.\d+\.\d+)?$/,
  78. use: 'file-loader',
  79. },
  80. ],
  81. },
  82. plugins: [
  83. DEVELOPMENT && new ErrorOverlayPlugin(),
  84. DEVELOPMENT && new HotModuleReplacementPlugin(),
  85. new CleanWebpackPlugin('dist'),
  86. new CopyWebpackPlugin([
  87. {
  88. from: './src/assets',
  89. to: './assets',
  90. ignore: [/\.(js|jsx|html|json)$/, '.gitkeep'],
  91. },
  92. ]),
  93. new HashedModuleIdsPlugin(),
  94. new DefinePlugin({
  95. 'process.env': Object.entries(ENVIRONMENT).reduce(
  96. (accum, [key, value]) => ({
  97. ...accum,
  98. [key]: JSON.stringify(value),
  99. }),
  100. {},
  101. ),
  102. }),
  103. new HtmlWebpackPlugin({
  104. title: 'Application',
  105. filename: 'index.html',
  106. template: path.resolve(SRC_PATH, 'index.html'),
  107. inject: true,
  108. meta: {
  109. description: 'React App',
  110. },
  111. minify: {
  112. // collapseWhitespace: true,
  113. processConditionalComments: true,
  114. keepClosingSlash: true,
  115. minifyCSS: true,
  116. minifyJS: true,
  117. minifyURLs: true,
  118. removeComments: true,
  119. removeRedundantAttributes: true,
  120. removeEmptyAttributes: true,
  121. removeStyleLinkTypeAttributes: true,
  122. useShortDoctype: true,
  123. },
  124. chunksSortMode: 'dependency',
  125. }),
  126. new ManifestPlugin(),
  127. new NamedModulesPlugin(),
  128. new OccurrenceOrderPlugin(true),
  129. new ForkTsCheckerWebpackPlugin({
  130. tslint: true,
  131. }),
  132. new BundleAnalyzerPlugin({
  133. analyzerMode: 'static',
  134. openAnalyzer: false,
  135. }),
  136. new ProvidePlugin({
  137. $: 'jquery',
  138. jQuery: 'jquery',
  139. }),
  140. ].filter(Boolean),
  141. devServer: {
  142. historyApiFallback: true,
  143. port: PORT,
  144. hot: true,
  145. },
  146. optimization: {
  147. splitChunks: {
  148. chunks: 'all',
  149. name: 'vendors',
  150. },
  151. },
  152. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement