webpack.config.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /**
  2. * React Static Boilerplate
  3. * https://github.com/koistya/react-static-boilerplate
  4. *
  5. * Copyright © 2015-2016 Konstantin Tarkus (@koistya)
  6. *
  7. * This source code is licensed under the MIT license found in the
  8. * LICENSE.txt file in the root directory of this source tree.
  9. */
  10. const path = require('path');
  11. const webpack = require('webpack');
  12. const extend = require('extend');
  13. const pkg = require('../package.json');
  14. const isDebug = !(process.argv.includes('--release') || process.argv.includes('-r'));
  15. const isVerbose = process.argv.includes('--verbose') || process.argv.includes('-v');
  16. /**
  17. * Webpack configuration (core/main.js => build/bundle.js)
  18. * http://webpack.github.io/docs/configuration.html
  19. */
  20. const config = {
  21. // The base directory
  22. context: path.resolve(__dirname, '../'),
  23. // The entry point for the bundle
  24. entry: ['./core/app.js'],
  25. // Options affecting the output of the compilation
  26. output: {
  27. path: path.resolve(__dirname, '../build'),
  28. publicPath: '/',
  29. file: 'build/[name].js',
  30. sourcePrefix: ' ',
  31. },
  32. // Switch loaders to debug or release mode
  33. debug: isDebug,
  34. // Developer tool to enhance debugging, source maps
  35. // http://webpack.github.io/docs/configuration.html#devtool
  36. devtool: isDebug ? 'source-map' : false,
  37. // What information should be printed to the console
  38. stats: {
  39. colors: true,
  40. reasons: isDebug,
  41. hash: isVerbose,
  42. version: isVerbose,
  43. timings: true,
  44. chunks: isVerbose,
  45. chunkModules: isVerbose,
  46. cached: isVerbose,
  47. cachedAssets: isVerbose,
  48. },
  49. // The list of plugins for Webpack compiler
  50. plugins: [
  51. new webpack.optimize.OccurenceOrderPlugin(),
  52. new webpack.DefinePlugin({
  53. 'process.env.NODE_ENV': isDebug ? '"development"' : '"production"',
  54. __DEV__: isDebug,
  55. }),
  56. ],
  57. // Options affecting the normal modules
  58. module: {
  59. loaders: [
  60. {
  61. test: /\.jsx?$/,
  62. include: [
  63. path.resolve(__dirname, '../components'),
  64. path.resolve(__dirname, '../core'),
  65. path.resolve(__dirname, '../routes'),
  66. ],
  67. loader: 'babel-loader',
  68. query: extend({}, pkg.babel, { babelrc: false }),
  69. },
  70. {
  71. test: /\.css/,
  72. loaders: [
  73. 'style-loader',
  74. `css-loader?${JSON.stringify({
  75. sourceMap: isDebug,
  76. // CSS Modules https://github.com/css-modules/css-modules
  77. modules: true,
  78. localIdentName: isDebug ? '[name]_[local]_[hash:base64:3]' : '[hash:base64:4]',
  79. // CSS Nano http://cssnano.co/options/
  80. minimize: !isDebug,
  81. })}`,
  82. 'postcss-loader',
  83. ],
  84. },
  85. {
  86. test: /\.json$/,
  87. loader: 'json-loader',
  88. },
  89. {
  90. test: /\.md$/,
  91. loader: path.resolve(__dirname, './webpack.markdown-loader.js'),
  92. },
  93. {
  94. test: /\.(png|jpg|jpeg|gif|svg|woff|woff2)$/,
  95. loader: 'url-loader?limit=10000',
  96. },
  97. {
  98. test: /\.(eot|ttf|wav|mp3)$/,
  99. loader: 'file-loader',
  100. },
  101. ],
  102. },
  103. // The list of plugins for PostCSS
  104. // https://github.com/postcss/postcss
  105. postcss(bundler) {
  106. return [
  107. require('postcss-import')({ addDependencyTo: bundler }),
  108. require('postcss-custom-properties')(),
  109. require('postcss-calc')(),
  110. require('postcss-color-function')(),
  111. require('pleeease-filters')(),
  112. require('pixrem')(),
  113. require('postcss-pseudoelements')(),
  114. require('postcss-selector-not')(),
  115. require('autoprefixer')(),
  116. ];
  117. },
  118. };
  119. // Optimize the bundle in release (production) mode
  120. if (!isDebug) {
  121. config.plugins.push(new webpack.optimize.DedupePlugin());
  122. config.plugins.push(new webpack.optimize.UglifyJsPlugin({ compress: { warnings: isVerbose } }));
  123. config.plugins.push(new webpack.optimize.AggressiveMergingPlugin());
  124. }
  125. module.exports = config;