Advertisement
moonion_nashivan

webpack

Nov 18th, 2019
191
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. const HtmlWebpackPlugin = require('html-webpack-plugin');
  4. const CopyWebpackPlugin = require('copy-webpack-plugin');
  5. const { CleanWebpackPlugin } = require('clean-webpack-plugin');
  6. const env = require('./config');
  7.  
  8. const NODE_ENV = process.env.NODE_ENV || 'production';
  9.  
  10. const WORKDIR = __dirname;
  11.  
  12.  
  13. const publicPath = path.resolve(WORKDIR, 'dist');
  14.  
  15. let config = {
  16.     mode: NODE_ENV,
  17.     entry: {
  18.         client: path.resolve(WORKDIR, 'src/index.jsx'),
  19.     },
  20.  
  21.     output: {
  22.         filename: 'js/[name].bundle.js',
  23.         chunkFilename: 'js/[name].chunkhash.bundle.js',
  24.         publicPath: '/',
  25.         path: publicPath,
  26.         library: '[name]',
  27.     },
  28.     optimization: {
  29.         splitChunks: {
  30.             cacheGroups: {
  31.                 commons: {
  32.                     test: /[\\/]node_modules[\\/]/,
  33.                     name: 'vendor',
  34.                     chunks: 'all'
  35.                 },
  36.             }
  37.         },
  38.         runtimeChunk: true
  39.     },
  40.     devtool: NODE_ENV === 'production' ? false : 'source-map',
  41.     module: {
  42.         rules: [
  43.             {
  44.                 test: /\.jsx?$/,
  45.                 exclude: /node_modules/,
  46.                 use: ["babel-loader", "eslint-loader"]
  47.             },
  48.             {test: /\.(png|jpg|gif|svg)$/, loader: 'file-loader?name=img/[name]-[sha512:hash:base64:7].[ext]'},
  49.             {
  50.                 test: /\.(ttf|otf|eot|woff(2)?)(\?[a-z0-9]+)?$/,
  51.                 loader: 'file-loader?name=fonts/[name]-[sha512:hash:base64:7].[ext]'
  52.             }
  53.         ]
  54.     },
  55.     resolve: {
  56.         extensions: ['*', '.js', '.jsx'],
  57.         alias: {
  58.             stylesheet: path.resolve(__dirname, 'src/common/Theme'),
  59.             mediaQuery: path.resolve(__dirname, 'src/utils/MediaQuery'),
  60.         },
  61.     },
  62.     plugins: [
  63.         new CleanWebpackPlugin(),
  64.         new webpack.EnvironmentPlugin(env),
  65.         new CopyWebpackPlugin([
  66.             // {from: './src/common/components/Icon/assets/icons', to: 'public/icons'},
  67.             // {from: './src/assets/favicons', to: ''},
  68.             // {from: './src/assets/images', to: 'public/images'},
  69.         ]),
  70.         new HtmlWebpackPlugin({
  71.             title: "Lvle Up Portal",
  72.             filename:  path.resolve(WORKDIR, 'dist/index.html'),
  73.             template:  path.resolve(WORKDIR, 'src/index.ejs'),
  74.             hash: true,
  75.             cache: NODE_ENV === 'production'
  76.         })
  77.     ],
  78.     devServer: {
  79.         historyApiFallback: true
  80.     }
  81. };
  82.  
  83. module.exports = config;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement