webpack.config.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. const path = require('path');
  2. const HtmlWebpackPlugin = require('html-webpack-plugin');
  3. const CleanWebpackPlugin = require("clean-webpack-plugin");
  4. const ExtractTextPlugin = require('extract-text-webpack-plugin');
  5. const autoprefixer = require('autoprefixer');
  6. const outputDirectory = "build";
  7. module.exports = {
  8. entry: './src/index.js',
  9. output: {
  10. path: path.resolve(__dirname, outputDirectory),
  11. filename: 'index.js',
  12. },
  13. devtool: 'source-map',
  14. module: {
  15. rules: [
  16. {
  17. test: /\.jsx?$/,
  18. exclude: /node_modules/,
  19. use: [
  20. {
  21. loader: 'babel-loader',
  22. options: {
  23. presets: ['react']
  24. }
  25. }
  26. ]
  27. },
  28. {
  29. test: /\.(sa|sc|c)ss$/,
  30. use: ExtractTextPlugin.extract({
  31. fallback: 'style-loader',
  32. use: [
  33. {
  34. loader: "css-loader",
  35. options: {
  36. sourceMap: true
  37. }
  38. },
  39. {
  40. loader: 'postcss-loader',
  41. options: {
  42. plugins: [
  43. autoprefixer({
  44. Browserslist: [
  45. '>1%',
  46. 'last 4 versions',
  47. 'Firefox ESR',
  48. 'not ie < 9', // React doesn't support IE8 anyway
  49. ]
  50. })
  51. ],
  52. sourceMap: true
  53. }
  54. },
  55. {
  56. loader: "sass-loader",
  57. options: {
  58. sourceMap: true
  59. }
  60. }
  61. ]
  62. })
  63. },
  64. {
  65. test: /\.(cur|ico|jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2)(\?.*)?$/,
  66. use: {
  67. loader: 'file-loader',
  68. query: {
  69. name: '[name].[hash:8].[ext]',
  70. outputPath: './assets/media/',
  71. publicPath: '/'
  72. }
  73. }
  74. },
  75. {
  76. test: /\.(mp4|webm|wav|mp3|m4a|aac|oga)(\?.*)?$/,
  77. use: {
  78. loader: 'url-loader',
  79. query: {
  80. limit: 10000,
  81. name: '[name].[hash:8].[ext]',
  82. outputPath: './assets/media/',
  83. publicPath: '/'
  84. }
  85. }
  86. }
  87. ]
  88. },
  89. plugins: [
  90. new CleanWebpackPlugin([outputDirectory]),
  91. new ExtractTextPlugin({
  92. filename: 'assets/css/[name].[contenthash:8].css'
  93. }),
  94. // new HtmlWebpackPlugin({
  95. // template: './public/index.html',
  96. // title: 'Production',
  97. // favicon: "./public/favicons/favicon.ico"
  98. // })
  99. ]
  100. };