Advertisement
moonion_nashivan

Untitled

Mar 21st, 2018
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const NODE_ENV = process.env.NODE_ENV || 'development';
  2. const path = require('path');
  3. const webpack = require('webpack');
  4. const HtmlWebpackPlugin = require('html-webpack-plugin');
  5. const CopyWebpackPlugin = require('copy-webpack-plugin');
  6. const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
  7. const ExtractTextPlugin = require('extract-text-webpack-plugin');
  8.  
  9. let config = {
  10.     entry: {
  11.         app: ["babel-polyfill", 'whatwg-fetch', './src/client.js'],
  12.     },
  13.  
  14.     output: {
  15.         filename: 'js/[name].js',
  16.         publicPath: '/',
  17.         path: '/var/www/web',
  18.         library: '[name]'
  19.     },
  20.     devtool: 'source-map',
  21.     module: {
  22.         loaders: [
  23.             {
  24.                 test: /\.jsx?$/,
  25.                 use: {
  26.                     loader: 'babel-loader',
  27.                     options: {
  28.                         presets: ['env', 'es2015', 'stage-2', 'react-app'],
  29.  
  30.                         babelrc: false
  31.                     }
  32.                 }
  33.             },
  34.             {test: /\.(png|jpg|gif|svg)$/, loader: 'file-loader?name=img/[name]-[sha512:hash:base64:7].[ext]'},
  35.             {
  36.                 test: /\.(ttf|otf|eot|woff(2)?)(\?[a-z0-9]+)?$/,
  37.                 loader: 'file-loader?name=fonts/[name]-[sha512:hash:base64:7].[ext]'
  38.             },
  39.             {
  40.                 test: /\.css$/,
  41.                 use: ExtractTextPlugin.extract({
  42.                     fallback: "style-loader",
  43.                     use: "css-loader"
  44.                 })
  45.             }
  46.  
  47.         ]
  48.     },
  49.     plugins: [
  50.         new webpack.EnvironmentPlugin(['NODE_ENV']),
  51.         new webpack.optimize.CommonsChunkPlugin({
  52.             name: "app",
  53.             minChunks: function (module, count) {
  54.                 return (!module.context || !module.context.includes("node_modules")) && count >= 2;
  55.             }
  56.         }),
  57.         new webpack.optimize.CommonsChunkPlugin({
  58.             name: "vendor",
  59.             chunks: ['app'],
  60.             minChunks: function(module){
  61.                 return module.context && module.context.includes("node_modules");
  62.             }
  63.         }),
  64.         new ExtractTextPlugin('css/styles.css'),
  65.         new CopyWebpackPlugin([
  66.             {from: './src/assets', to: 'public'},
  67.             {from: './src/assets/favicon', to: ''}
  68.         ]),
  69.         new HtmlWebpackPlugin({
  70.             title: 'Bitrent',
  71.             template: 'src/index.ejs',
  72.             hash: true,
  73.             cache: false
  74.         })
  75.     ]
  76. };
  77.  
  78. if (NODE_ENV === 'production') {
  79.     config.plugins.push(
  80.         new UglifyJsPlugin({})
  81.     );
  82.     config.devtool = false;
  83. }
  84.  
  85.  
  86. module.exports = config;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement