Guest User

Untitled

a guest
Jul 20th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.99 KB | None | 0 0
  1. const path = require('path')
  2. const webpack = require('webpack')
  3. const HtmlWebPackPlugin = require('html-webpack-plugin')
  4. const ExtractTextPlugin = require('extract-text-webpack-plugin')
  5. // const MiniCssExtractPlugin = require('mini-css-extract-plugin')
  6. const HtmlWebpackExcludeEmptyAssetsPlugin = require('html-webpack-exclude-empty-assets-plugin')
  7.  
  8. module.exports = {
  9. context: path.resolve(__dirname, 'source'),
  10. entry: {
  11. index: './index.js',
  12. vendor: [
  13. 'babel-polyfill',
  14. 'axios',
  15. 'react',
  16. 'react-dom',
  17. 'prop-types',
  18. 'react-router-dom',
  19. ],
  20. },
  21. output: {
  22. filename: '[name]-[hash].bundle.js',
  23. path: path.resolve(__dirname, 'dist'),
  24. publicPath: '/',
  25. },
  26. resolve: {
  27. modules: ['source', 'node_modules'],
  28. alias: {
  29. images: path.resolve(__dirname, 'source/assets/images'),
  30. },
  31. },
  32. module: {
  33. rules: [
  34. {
  35. test: /\.js$/,
  36. use: 'babel-loader',
  37. exclude: /node_modules/,
  38. use: ['babel-loader'],
  39. },
  40. // { test: /\.(jpg|jpeg|gif|png)$/, use: { loader: 'url-loader', options: { limit: 20000 } } },
  41. {
  42. test: /\.(jpe?g|gif|png|svg|ttf|ico)$/,
  43. use: {
  44. loader: 'file-loader',
  45. options: { name: '[path][name].[ext]' },
  46. },
  47. },
  48. {
  49. test: /\.(svg|ttf|eot|woff2?)(\?[a-z0-9=&.]+)?$/,
  50. loader: 'file-loader',
  51. },
  52. // { test: /\.css$/, use: 'css-loader', include: /source/ },
  53. {
  54. test: /\.css$/,
  55. exclude: /node_modules/,
  56. use: ExtractTextPlugin.extract({
  57. fallback: 'style-loader',
  58. use: [
  59. {
  60. loader: 'css-loader',
  61. options: {
  62. importLoaders: 1,
  63. modules: true,
  64. sourceMap: true,
  65. localIdentName: '[local]',
  66. },
  67. },
  68. { loader: 'postcss-loader', options: { sourceMap: true } },
  69. ],
  70. publicPath: '/',
  71. }),
  72. },
  73. // {
  74. // test: /\.css$/,
  75. // exclude: /node_modules/,
  76. // use: [
  77. // {
  78. // loader: MiniCssExtractPlugin.loader,
  79. // options: {
  80. // // you can specify a publicPath here
  81. // // by default it use publicPath in webpackOptions.output
  82. // publicPath: '/',
  83. // },
  84. // },
  85. // {
  86. // loader: 'css-loader',
  87. // options: {
  88. // importLoaders: 1,
  89. // modules: true,
  90. // sourceMap: true,
  91. // localIdentName: '[path]-[local]',
  92. // },
  93. // },
  94. // { loader: 'postcss-loader', options: { sourceMap: true } },
  95. // ],
  96. // },
  97. ],
  98. },
  99. optimization: {
  100. splitChunks: {
  101. // include all types of chunks
  102. chunks: 'all',
  103. },
  104. },
  105. plugins: [
  106. new ExtractTextPlugin('[name]-[hash].bundle.css', {
  107. allChunks: true,
  108. }),
  109. // new MiniCssExtractPlugin({
  110. // filename: '[name]-[hash].bundle.css',
  111. // chunkFilename: '[id].[hash].css',
  112. // }),
  113. new HtmlWebPackPlugin({
  114. title: 'Melika',
  115. template: path.resolve('./', 'index.ejs'),
  116. filename: 'index.html',
  117. inject: 'body',
  118. favicon: path.resolve('./', 'favicon.ico'),
  119. files: {
  120. css: ['[name]-[hash].bundle.css'],
  121. js: ['vendor-[hash].bundle.js', 'index-[hash].bundle.js'],
  122. chunks: {
  123. vendor: {
  124. entry: 'vendor-[hash].bundle.js',
  125. css: [],
  126. },
  127. index: {
  128. entry: 'index-[hash].bundle.js',
  129. css: [],
  130. },
  131. },
  132. },
  133. }),
  134. new HtmlWebpackExcludeEmptyAssetsPlugin(),
  135. new webpack.HotModuleReplacementPlugin(),
  136. new webpack.LoaderOptionsPlugin({
  137. debug: true,
  138. }),
  139. ],
  140. devtool: 'cheap-module-eval-source-map',
  141. devServer: {
  142. contentBase: path.resolve(process.cwd(), 'dist'),
  143. publicPath: '/',
  144. port: 4789,
  145. hotOnly: true,
  146. inline: true,
  147. historyApiFallback: true,
  148. stats: 'errors-only',
  149. },
  150. }
Add Comment
Please, Sign In to add comment