Guest User

Untitled

a guest
Sep 21st, 2018
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.71 KB | None | 0 0
  1. const fs = require('fs')
  2. const path = require('path')
  3. const ManifestPlugin = require('webpack-manifest-plugin')
  4. const ExtractTextPlugin = require('extract-text-webpack-plugin')
  5. const webpack = require('webpack')
  6. const CopyWebpackPlugin = require('copy-webpack-plugin')
  7. const ModernizrWebpackPlugin = require('modernizr-webpack-plugin')
  8. const HtmlWebpackPlugin = require('html-webpack-plugin')
  9. const Dotenv = require('dotenv-webpack')
  10.  
  11. const APP_DIR = path.resolve(__dirname, '..', 'src')
  12. const BUILD_DIR = path.resolve(__dirname, '..', 'dist')
  13. const PROD_ENV = process.env.NODE_ENV === 'production'
  14. const ENV_FILE = process.env.ENV_FILE
  15.  
  16. const envFilePath = (ENV_FILE) ? `./.env.${ENV_FILE}` : './.env'
  17.  
  18. require('dotenv').config({
  19. path: envFilePath
  20. })
  21.  
  22. const extractStyles = new ExtractTextPlugin({
  23. filename: 'styles.[md5:contenthash:hex:8].css',
  24. ignoreOrder: true,
  25. allChunks: true,
  26. })
  27.  
  28. module.exports = {
  29. entry: [
  30. '@babel/polyfill',
  31. `${APP_DIR}/index.tsx`
  32. ],
  33. devtool: 'source-map',
  34. mode: 'production',
  35. output: {
  36. path: BUILD_DIR,
  37. filename: '[name].[hash].js'
  38. },
  39. module: {
  40. rules: [
  41. {
  42. test: /\.(jpe?g|png|gif|svg)$/i,
  43. use: [
  44. 'file-loader?hash=sha512&digest=hex&name=[hash].[ext]'
  45. ]
  46. },
  47. {
  48. test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/,
  49. use: 'url-loader?limit=10000&mimetype=application/font-woff'
  50. },
  51. {
  52. test: /\.(ttf|eot|otf)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
  53. use: 'file-loader'
  54. },
  55. {
  56. test: /\.hbs$/,
  57. loader : 'handlebars-loader',
  58. options: {
  59. knownHelpersOnly: false,
  60. inlineRequires: '/images/',
  61. },
  62. },
  63. {
  64. test: /\.tsx?$/,
  65. use: 'ts-loader',
  66. exclude: /node_modules/
  67. },
  68. {
  69. test: /src\/(.*)\.s?css$/,
  70. use: extractStyles.extract({
  71. fallback: 'style-loader?sourceMap',
  72. use: [
  73. {
  74. loader: 'css-loader',
  75. options: {
  76. localIdentName: '[hash:base64:6]',
  77. modules: true,
  78. importLoaders: 1,
  79. minimize: {
  80. discardComments: {
  81. removeAll: true
  82. }
  83. },
  84. sourceMap: true
  85. }
  86. },
  87. 'postcss-loader?sourceMap',
  88. 'resolve-url-loader?sourceMap',
  89. 'sass-loader?sourceMap'
  90. ]
  91. })
  92. },
  93. {
  94. test: /node_modules\/(.*)\.s?css$/,
  95. exclude: /src\/(.*)\.scss$/,
  96. use: extractStyles.extract({
  97. fallback: 'style-loader?sourceMap',
  98. use: [
  99. {
  100. loader: 'css-loader',
  101. options: {
  102. minimize: {
  103. discardComments: {
  104. removeAll: true
  105. }
  106. },
  107. sourceMap: true
  108. }
  109. },
  110. 'postcss-loader?sourceMap',
  111. 'resolve-url-loader?sourceMap',
  112. 'sass-loader?sourceMap'
  113. ]
  114. })
  115. }
  116. ]
  117. },
  118. resolve: {
  119. extensions: ['.ts', '.tsx', '.js', '.json'],
  120. },
  121. plugins: [
  122. new Dotenv({
  123. systemvars: true,
  124. path: envFilePath
  125. }),
  126. new webpack.NoEmitOnErrorsPlugin(),
  127. new HtmlWebpackPlugin({
  128. filename: 'index.html',
  129. template: `${APP_DIR}/index.hbs`,
  130. production: PROD_ENV
  131. }),
  132. new CopyWebpackPlugin([{
  133. from: './src/public'
  134. }]),
  135. new ModernizrWebpackPlugin({
  136. options: [
  137. 'setClasses'
  138. ],
  139. filename: 'modernizr[hash]',
  140. noChunk: true,
  141. htmlWebpackPlugin: true
  142. }),
  143. extractStyles,
  144. ],
  145. optimization: {
  146. splitChunks: {
  147. name: 'vendor',
  148. chunks: 'all'
  149. }
  150. }
  151. }
Add Comment
Please, Sign In to add comment