config.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /**
  2. * React Static Boilerplate
  3. * https://github.com/koistya/react-static-boilerplate
  4. * Copyright (c) Konstantin Tarkus (@koistya) | MIT license
  5. */
  6. import path from 'path';
  7. import minimist from 'minimist';
  8. import webpack from 'webpack';
  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 WATCH = global.watch;
  15. const SCRIPT_LOADERS = WATCH ? ['react-hot', 'babel'] : ['babel'];
  16. const AUTOPREFIXER_BROWSERS = [
  17. 'Android 2.3',
  18. 'Android >= 4',
  19. 'Chrome >= 20',
  20. 'Firefox >= 24',
  21. 'Explorer >= 8',
  22. 'iOS >= 6',
  23. 'Opera >= 12',
  24. 'Safari >= 6'
  25. ];
  26. // Base configuration
  27. const config = {
  28. output: {
  29. path: path.join(__dirname, '../build'),
  30. publicPath: '/',
  31. sourcePrefix: ' '
  32. },
  33. cache: false,
  34. debug: DEBUG,
  35. stats: {
  36. colors: true,
  37. reasons: DEBUG,
  38. hash: VERBOSE,
  39. version: VERBOSE,
  40. timings: VERBOSE,
  41. chunks: VERBOSE,
  42. chunkModules: VERBOSE,
  43. cached: VERBOSE,
  44. cachedAssets: VERBOSE
  45. },
  46. plugins: [
  47. new webpack.optimize.OccurenceOrderPlugin(),
  48. new webpack.DefinePlugin({
  49. 'process.env.NODE_ENV': DEBUG ? '"development"' : '"production"',
  50. '__DEV__': DEBUG
  51. })
  52. ],
  53. module: {
  54. loaders: [{
  55. test: /\.css$/,
  56. loader: 'style-loader/useable!' +
  57. 'css-loader' + (DEBUG ? '' : '/minimize') + '!postcss-loader'
  58. }, {
  59. test: /\.jsx?$/,
  60. include: [
  61. path.resolve(__dirname, '../src')
  62. ],
  63. loaders: SCRIPT_LOADERS
  64. }, {
  65. test: /[\\\/]app\.js$/,
  66. loader: path.join(__dirname, './lib/routes-loader.js')
  67. }, {
  68. test: /\.gif/,
  69. loader: 'url-loader?limit=10000&mimetype=image/gif'
  70. }, {
  71. test: /\.jpg/,
  72. loader: 'url-loader?limit=10000&mimetype=image/jpg'
  73. }, {
  74. test: /\.png/,
  75. loader: 'url-loader?limit=10000&mimetype=image/png'
  76. }, {
  77. test: /\.svg/,
  78. loader: 'url-loader?limit=10000&mimetype=image/svg+xml'
  79. }]
  80. },
  81. postcss: [autoprefixer(AUTOPREFIXER_BROWSERS)]
  82. };
  83. // Configuration for the client-side bundle
  84. const appConfig = merge({}, config, {
  85. entry: (WATCH ? [
  86. 'webpack/hot/dev-server',
  87. 'webpack-hot-middleware/client'
  88. ] : []).concat([
  89. './src/js/app.js'
  90. ]),
  91. output: {
  92. filename: 'app.js'
  93. },
  94. plugins: config.plugins.concat(WATCH ? [
  95. new webpack.HotModuleReplacementPlugin(),
  96. new webpack.NoErrorsPlugin()
  97. ] : [])
  98. });
  99. // Configuration for server-side pre-rendering bundle
  100. const pagesConfig = merge({}, config, {
  101. entry: './src/js/app.js',
  102. output: {
  103. filename: 'app.node.js',
  104. libraryTarget: 'commonjs2'
  105. },
  106. target: 'node',
  107. externals: /^[a-z][a-z\.\-\/0-9]*$/i,
  108. plugins: config.plugins.concat([
  109. new webpack.optimize.LimitChunkCountPlugin({ maxChunks: 1 })
  110. ]),
  111. node: {
  112. console: false,
  113. global: false,
  114. process: false,
  115. Buffer: false,
  116. __filename: false,
  117. __dirname: false
  118. }
  119. });
  120. export default [appConfig, pagesConfig];