Advertisement
Guest User

Untitled

a guest
Aug 26th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.18 KB | None | 0 0
  1. import webpack from 'webpack'
  2. import path from 'path'
  3. import HtmlWebpackPlugin from 'html-webpack-plugin'
  4. import autoprefixer from 'autoprefixer'
  5. import ExtractTextPlugin from 'extract-text-webpack-plugin'
  6.  
  7. const LAUNCH_COMMAND = process.env.npm_lifecycle_event
  8.  
  9. const isProduction = LAUNCH_COMMAND === 'production'
  10. process.env.BABEL_ENV = LAUNCH_COMMAND
  11.  
  12. const PATHS = {
  13. root: path.join(__dirname),
  14. app: path.join(__dirname, 'app'),
  15. build: path.join(__dirname, 'dist')
  16. }
  17.  
  18. const HTMLWebpackPluginConfig = new HtmlWebpackPlugin({
  19. template: PATHS.app + '/index.html',
  20. filename: 'index.html',
  21. inject: 'body'
  22. })
  23.  
  24. const productionPlugin = new webpack.DefinePlugin({
  25. 'process.env': {
  26. NODE_ENV: JSON.stringify('production')
  27. }
  28. })
  29.  
  30. const productionPlugin2 = new webpack.optimize.UglifyJsPlugin({
  31. compressor: {
  32. warnings: false
  33. }
  34. })
  35.  
  36. const productionPlugin3 = new ExtractTextPlugin('style.css')
  37.  
  38. const base = {
  39. entry: [
  40. 'babel-polyfill',
  41. PATHS.app
  42. ],
  43. output: {
  44. path: PATHS.build,
  45. filename: 'index_bundle.js'
  46. },
  47. postcss: [ autoprefixer({ browsers: ['last 2 versions'] }) ],
  48. resolve: {
  49. root: path.resolve('./app')
  50. }
  51. }
  52.  
  53. const developmentConfig = {
  54. devtool: 'cheap-module-inline-source-map',
  55. module: {
  56. loaders: [
  57. {test: /.js$/, exclude: /node_modules/, loader: 'babel-loader'},
  58. {test: /.css$/, loader: 'style!css?sourceMap&modules&localIdentName=[name]__[local]___[hash:base64:5]&importLoader=1!postcss'}
  59. ]
  60. },
  61. devServer: {
  62. contentBase: PATHS.build,
  63. historyApiFallback: true,
  64. hot: true,
  65. inline: true,
  66. progress: true
  67. },
  68. plugins: [HTMLWebpackPluginConfig, new webpack.HotModuleReplacementPlugin()]
  69. }
  70.  
  71. const productionConfig = {
  72. devtool: 'cheap-module-source-map',
  73. module: {
  74. loaders: [
  75. {test: /.js$/, exclude: /node_modules/, loader: 'babel-loader'},
  76. { test: /.css$/, loader: ExtractTextPlugin.extract('css?sourceMap&modules&localIdentName=[name]__[local]___[hash:base64:5]&importLoader=1!postcss') }
  77. ]
  78. },
  79. plugins: [HTMLWebpackPluginConfig, productionPlugin, productionPlugin2, productionPlugin3]
  80. }
  81.  
  82. export default Object.assign({}, base, isProduction === true ? productionConfig : developmentConfig)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement