Advertisement
ahmadandika

webpack

Aug 18th, 2019
440
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const path = require('path');
  2. const HtmlWebpackPlugin = require('html-webpack-plugin');
  3. const MiniCssExtractPlugin = require('mini-css-extract-plugin');
  4. const webpack = require('webpack');
  5. const Dotenv = require('dotenv-webpack');
  6.  
  7. module.exports = {
  8.   entry: './src/index.js',
  9.   output: {
  10.     path: path.resolve('dist'),
  11.     filename: '[name].[contenthash].js',
  12.     publicPath: '/'
  13.   },
  14.   devtool: 'source-map',
  15.   resolveLoader: {
  16.     moduleExtensions: ['-loader']
  17.   },
  18.   resolve: {
  19.     extensions: ['.js', '.jsx']
  20.   },
  21.   module: {
  22.     rules: [
  23.       {
  24.         test: [/\.jsx$/, /\.js$/],
  25.         exclude: /node_modules/,
  26.         loader: 'babel-loader',
  27.         query: {
  28.           presets: ['es2015', 'react', 'stage-0', 'stage-2']
  29.         }
  30.       },
  31.       {
  32.         test: /\.html$/,
  33.         exclude: /node_modules/,
  34.         loader: 'html-loader'
  35.       },
  36.       {
  37.         test: /\.(eot|woff|woff2|ttf|svg|png|jpg|gif)$/,
  38.         use: [
  39.           {
  40.             loader: 'file-loader'
  41.           }
  42.         ]
  43.       },
  44.       {
  45.         test: /\.css$/,
  46.         exclude: /node_modules/,
  47.         use: ['style-loader', 'css-loader']
  48.       },
  49.       {
  50.         test: /\.scss$/,
  51.         use: [
  52.           {
  53.             loader: 'style-loader'
  54.           },
  55.           {
  56.             loader: 'css-loader',
  57.             options: {
  58.               sourceMap: true
  59.             }
  60.           },
  61.           {
  62.             loader: 'sass-loader',
  63.             options: {
  64.               sourceMap: true
  65.             }
  66.           }
  67.         ]
  68.       },
  69.       {
  70.         test: /\.s?[ac]ss$/,
  71.         use: [
  72.           MiniCssExtractPlugin.loader,
  73.           { loader: 'css-loader', options: { url: false, sourceMap: true } },
  74.           { loader: 'sass-loader', options: { sourceMap: true } }
  75.         ]
  76.       }
  77.     ]
  78.   },
  79.   devServer: {
  80.     historyApiFallback: true,
  81.     port: 8000
  82.   },
  83.   optimization: {
  84.     splitChunks: {
  85.       cacheGroups: {
  86.         commons: {
  87.           test: /[\\/]node_modules[\\/]/,
  88.           name: 'vendor',
  89.           chunks: 'all'
  90.         }
  91.       }
  92.     }
  93.   },
  94.   plugins: [
  95.     new HtmlWebpackPlugin({
  96.       template: './public/index.html',
  97.       filename: 'index.html'
  98.     }),
  99.     new MiniCssExtractPlugin({
  100.       filename: 'style.css'
  101.     }),
  102.     new Dotenv({
  103.       path: './.env' // Path to .env file (this is the default)
  104.     }),
  105.     new webpack.DefinePlugin({
  106.       'process.env.BROWSER': true,
  107.       'process.env.URL_API': JSON.stringify(process.env.URL_API)
  108.     })
  109.   ]
  110. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement