Guest User

Untitled

a guest
Aug 1st, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const path = require('path');
  2. const webpack = require('webpack');
  3. //plugin for analyzing js bundle file. helps to make file size under control by identifying large libraries
  4. const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
  5. const ExtractTextPlugin = require("extract-text-webpack-plugin");
  6. const env = require('node-env-file');
  7.  
  8. env(path.resolve(`.env`));
  9.  
  10. const analyzeBundles = new BundleAnalyzerPlugin({
  11.   analyzerMode: 'static',
  12.   reportFilename: 'report.html', //look into /dist folder
  13.   openAnalyzer: false,
  14.   generateStatsFile: false,
  15. });
  16. const definePlugin = new webpack.DefinePlugin({
  17.   'process.env': {
  18.     'NODE_ENV': JSON.stringify(process.env.NODE_ENV),
  19.     'FACEBOOK_APP_ID': JSON.stringify(process.env.FACEBOOK_APP_ID),
  20.     'RECAPTCHA_SITE_KEY': JSON.stringify(process.env.RECAPTCHA_SITE_KEY),
  21.     'GOOGLE_OAUTH_CLIEN_ID': JSON.stringify(process.env.GOOGLE_OAUTH_CLIEN_ID),
  22.     'GOOGLE_MAPS_API_KEY': JSON.stringify(process.env.GOOGLE_MAPS_API_KEY),
  23.     'DRAUGIEM_APP_ID': JSON.stringify(process.env.DRAUGIEM_APP_ID),
  24.     'DRAUGIEM_API_KEY': JSON.stringify(process.env.DRAUGIEM_API_KEY),
  25.   }
  26. });
  27. const uglifyPlugin = new webpack.optimize.UglifyJsPlugin({
  28.   compress:{
  29.     warnings: true
  30.   }
  31. });
  32. const mergePlugin = new webpack.optimize.AggressiveMergingPlugin();
  33. const sourceMapPlugin = new webpack.SourceMapDevToolPlugin();
  34. const extractTextPlugin = new ExtractTextPlugin('[name].css');
  35. const ignorePlugin = new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/);
  36.  
  37. const isDevelopment = process.env.NODE_ENV !== 'production';
  38.  
  39. const config = {
  40.   watch: isDevelopment,
  41.   watchOptions: {
  42.     poll: 1000
  43.   },
  44.   devtool: isDevelopment ? 'eval' : false,
  45.   entry: {
  46.     bundle: path.join(`${__dirname}/web/js/entry.js`),
  47.   },
  48.   output: {
  49.     path: path.join(`${__dirname}/web/dist`), //distribution directory
  50.     filename: "[name].js" //bundle file name
  51.   },
  52.   module: {
  53.     loaders: [
  54.       {
  55.         test: /\.js$/,
  56.         exclude: /node_modules/,
  57.         loaders: ['babel-loader', 'eslint-loader'],
  58.       },
  59.       {
  60.         test: /\.css$/,
  61.         loader: ExtractTextPlugin.extract({
  62.           use: ['css-loader', 'postcss-loader']
  63.         }),
  64.       },
  65.     ],
  66.   },
  67.   plugins: isDevelopment ? [
  68.     ignorePlugin,
  69.     definePlugin,
  70.     extractTextPlugin,
  71.     analyzeBundles,
  72.     sourceMapPlugin,
  73.   ] : [
  74.     ignorePlugin,
  75.     definePlugin,
  76.     extractTextPlugin,
  77.     uglifyPlugin,
  78.     mergePlugin,
  79.     analyzeBundles
  80.   ],
  81.   devServer: {
  82.     contentBase: path.resolve(__dirname, 'web/build'),
  83.         watchContentBase: true,
  84.         overlay: true
  85.   }
  86. };
  87.  
  88. module.exports = config;
Advertisement
Add Comment
Please, Sign In to add comment