Advertisement
Guest User

webpack.config.js

a guest
May 22nd, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const HtmlWebpackPlugin = require("html-webpack-plugin");
  2. const webpack = require("webpack");
  3. const ExtractTextPlugin = require("extract-text-webpack-plugin");
  4. const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
  5. const path = require("path");
  6. require("dotenv").config();
  7.  
  8. var configFunc = function(){
  9.     var config = {
  10.         optimization: {
  11.             minimizer: [new UglifyJsPlugin()],
  12.             splitChunks: {
  13.                 cacheGroups: {
  14.                     commons: {
  15.                         name: "commons",
  16.                         filename: "commons.js"
  17.                     }
  18.                 }
  19.             }
  20.         },
  21.         devtool: "source-map",
  22.         entry: [
  23.             __dirname + "/app/app.js"
  24.         ],
  25.         output: {
  26.             path: __dirname + "/dist",
  27.             filename: "bundle.js",
  28.             publicPath: "/"
  29.         },
  30.         devServer: {
  31.             historyApiFallback: true,
  32.             contentBase: './',
  33.             hot: true
  34.         },
  35.         module: {
  36.             rules: [
  37.                 {
  38.                     test: /\.js$/,
  39.                     use: "babel-loader",
  40.                     exclude: [/node_modules/]
  41.                 },
  42.                 {
  43.                     test: /\.(sass|scss|css)$/,
  44.                     use: [
  45.                         {
  46.                             loader: "style-loader" // creates style nodes from JS strings
  47.                         },
  48.                         {
  49.                             loader: "css-loader" // translates CSS into CommonJS
  50.                         }
  51.                     ]
  52.                 }
  53.             ]
  54.         },
  55.         plugins: [
  56.             new HtmlWebpackPlugin({
  57.                 hash: true,
  58.                 template: path.join(__dirname , "/app/index.html"),
  59.                 inject: "body"
  60.             }),
  61.             new webpack.BannerPlugin("React Twilio"),
  62.             new ExtractTextPlugin("[name]-[hash].css")
  63.         ]};
  64.     if(process.env.NODE_ENV === "PROD") {
  65.         config.plugins.push(new UglifyJsPlugin());
  66.     }
  67.     if(process.env.NODE_ENV === "DEV") {
  68.         config.entry.push('webpack-hot-middleware/client?reload=true');
  69.         config.plugins.push(new webpack.HotModuleReplacementPlugin());
  70.     }
  71.     return config;
  72. }();
  73.  
  74. module.exports = configFunc;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement