webpack.config.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /**
  2. * React Static Boilerplate
  3. * Copyright (c) Konstantin Tarkus | MIT License
  4. */
  5. import path from 'path';
  6. import minimist from 'minimist';
  7. import webpack from 'webpack';
  8. import gutil from 'gulp-util';
  9. import autoprefixer from 'autoprefixer-core';
  10. import merge from 'lodash/object/merge';
  11. const argv = minimist(process.argv.slice(2));
  12. const DEBUG = !argv.release;
  13. const VERBOSE = !!argv.verbose;
  14. const AUTOPREFIXER_BROWSERS = [
  15. 'Android 2.3',
  16. 'Android >= 4',
  17. 'Chrome >= 20',
  18. 'Firefox >= 24',
  19. 'Explorer >= 8',
  20. 'iOS >= 6',
  21. 'Opera >= 12',
  22. 'Safari >= 6'
  23. ];
  24. // Base configuration
  25. const config = {
  26. output: {
  27. path: path.join(__dirname, 'build'),
  28. publicPath: './',
  29. sourcePrefix: ' '
  30. },
  31. cache: false,
  32. debug: DEBUG,
  33. stats: {
  34. colors: gutil.colors.supportsColor,
  35. reasons: DEBUG,
  36. hash: VERBOSE,
  37. version: VERBOSE,
  38. timings: VERBOSE,
  39. chunks: VERBOSE,
  40. chunkModules: VERBOSE,
  41. cached: VERBOSE,
  42. cachedAssets: VERBOSE
  43. },
  44. plugins: [
  45. new webpack.optimize.OccurenceOrderPlugin(),
  46. new webpack.DefinePlugin({
  47. 'process.env.NODE_ENV': DEBUG ? '"development"' : '"production"',
  48. '__DEV__': DEBUG
  49. })
  50. ],
  51. module: {
  52. loaders: [{
  53. test: /\.jsx?$/,
  54. exclude: /node_modules/,
  55. loader: 'babel-loader'
  56. }, {
  57. test: /routes\.jsx?$/,
  58. loader: './routes-loader.js'
  59. }]
  60. },
  61. postcss: [autoprefixer(AUTOPREFIXER_BROWSERS)]
  62. };
  63. // Configuration for the client-side bundle
  64. const appConfig = merge({}, config, {
  65. entry: ['./scripts/app.js'].concat(global.hot ? 'webpack/hot/dev-server' : []),
  66. output: {
  67. filename: 'app.js'
  68. }
  69. });
  70. // Configuration for server-side pre-rendering bundle
  71. const pagesConfig = merge({}, config, {
  72. entry: './scripts/pages.js',
  73. output: {
  74. filename: 'pages.js',
  75. libraryTarget: 'commonjs2'
  76. },
  77. target: 'node',
  78. externals: /^[a-z][a-z\.\-0-9]*$/,
  79. node: {
  80. console: false,
  81. global: false,
  82. process: false,
  83. Buffer: false,
  84. __filename: false,
  85. __dirname: false
  86. }
  87. });
  88. export default [appConfig, pagesConfig];