Advertisement
Guest User

Untitled

a guest
Feb 21st, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.62 KB | None | 0 0
  1. const path = require('path');
  2.  
  3. const merge = require('webpack-merge');
  4.  
  5. const TARGET = process.env.npm_lifecycle_event;
  6.  
  7. const PATHS = {
  8. app: path.join(__dirname, 'app'),
  9. build: path.join(__dirname, 'build')
  10.  
  11. };
  12.  
  13. process.env.BABEL_ENV = TARGET;
  14.  
  15. const common = {
  16. entry: {
  17. app: PATHS.app
  18. },
  19.  
  20. // Add resolve.extensions.
  21. // '' is needed to allow imports without an extension.
  22. // Note the .'s before extensions as it will fail to match without!!!
  23. resolve: {
  24. extensions: ['*', '.ts', '.js', '.jsx']
  25. },
  26.  
  27. output: {
  28. path: PATHS.build,
  29. filename: 'bundle.js'
  30. },
  31.  
  32. module: {
  33. loaders: [
  34. {
  35. // Test expects a RegExp! Note the slashes!
  36. test: /\.css$/,
  37. loaders:['style-loader','css-loader'],
  38. // Include accepts either a path or an array of paths
  39. include: PATHS.app
  40. },
  41.  
  42. {
  43. test: /\.woff($|\?)|\.woff2($|\?)|\.ttf($|\?)|\.eot($|\?)|\.svg($|\?)/,
  44. loaders:['url-loader','file-loader'],
  45. include: PATHS.app
  46. },
  47.  
  48. {
  49. test: /\.json$/,
  50. loaders:['json-loader'],
  51. include: PATHS.app
  52. },
  53.  
  54. {test: /bootstrap\/js\//, loader: 'imports?jQuery=jquery' },
  55.  
  56. // Set up jsx. This accepts js too thanks to RegExp
  57. {
  58. test: /\.jsx?$/,
  59. // Enable caching for improved performance during development
  60. // It uses default OS directory by default. If you need something
  61. // more custom, pass a path to it. I.e., babel?cacheDirectory=<path>
  62. loaders: ['babel-loader?cacheDirectory'],
  63. // Parse only app files! Without this it will go through entire project.
  64. // In addition to being slow, that will most likely result in an error.
  65. include: PATHS.app
  66. }
  67. ]
  68. }
  69.  
  70.  
  71. };
  72.  
  73. const webpack = require('webpack');
  74. const NpmInstallPlugin = require('npm-install-webpack-plugin');
  75.  
  76. if(TARGET === 'start' || !TARGET) {
  77. module.exports = merge(common, {
  78. devServer: {
  79. contentBase: PATHS.build,
  80.  
  81. //ENable history API fallback so HTML5 HIstory API based
  82. //routing works. Good default comes handy in complicated setups
  83. historyApiFallback: true,
  84. hot: true,
  85. inline: true,
  86. //progress: true,
  87.  
  88. // Display only errors to reduce amount of ouput**
  89. stats: 'errors-only'
  90. },
  91. plugins: [
  92. new webpack.HotModuleReplacementPlugin()
  93. ]
  94. });
  95. }
  96.  
  97. if(TARGET === 'build'){
  98. module.exports = merge(common, {
  99. devtools:'eval-source-map',
  100. });
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement