Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const path = require('path');
- const HtmlWebpackPlugin = require('html-webpack-plugin');
- const { CleanWebpackPlugin } = require('clean-webpack-plugin');
- const TerserPlugin = require('terser-webpack-plugin');
- const MiniCssExtractPlugin = require('mini-css-extract-plugin');
- const { DefinePlugin } = require('webpack');
- const dotEnv = require('dotenv').config();
- const isEnvProduction = process.env.NODE_ENV === 'production';
- module.exports = {
- mode: process.env.NODE_ENV,
- entry: {
- main: [ 'whatwg-fetch', '@babel/polyfill', './src/index.js' ],
- },
- output: {
- path: path.resolve(__dirname, 'build'),
- filename: isEnvProduction ? '[name].[hash:10].js' : '[name].js',
- chunkFilename: isEnvProduction ? '[name].[hash:10].chunk.js' : '[name].chunk.js',
- publicPath: '/',
- },
- resolve: {
- modules: [ path.resolve(__dirname, 'node_modules') ],
- ...require('./webpack.config.alias').resolve,
- },
- module: {
- rules: [
- {
- test: /\.(js|jsx)$/,
- exclude: [
- /node_modules\/(?!ansi-regex).*/,
- ],
- use: {
- loader: 'babel-loader',
- options: {
- presets: [
- [ '@babel/preset-env', { modules: false } ],
- '@babel/preset-react',
- ],
- plugins: [
- [
- 'babel-plugin-styled-components',
- {
- ssr: false,
- displayName: !isEnvProduction,
- fileName: false,
- minify: isEnvProduction,
- transpileTemplateLiterals: isEnvProduction,
- pure: false,
- },
- ],
- '@babel/plugin-transform-regenerator',
- '@babel/plugin-proposal-class-properties',
- ],
- },
- },
- },
- {
- test: /\.font\.js/,
- use: [
- MiniCssExtractPlugin.loader,
- 'css-loader',
- {
- loader: 'webfonts-loader',
- options: {
- fileName: '[name].[hash:8].[ext]',
- },
- },
- ],
- },
- {
- test: /\.(jpg|jpeg|png|gif|svg)$/,
- loader: 'file-loader',
- options: {
- name: '[name].[hash:8].[ext]',
- },
- },
- {
- test: /\.(ttf|eot|woff2?)$/,
- loader: 'file-loader',
- options: {
- name: '[name].[ext]',
- },
- },
- {
- test: /\.css$/i,
- use: [ 'style-loader', 'css-loader' ],
- },
- ],
- },
- devServer: {
- open: true,
- overlay: true,
- port: process.env.PORT,
- quiet: true,
- disableHostCheck: true,
- writeToDisk: true,
- historyApiFallback: true,
- proxy: {
- '/api': {
- target: process.env.PROXY_URL,
- },
- '/uploads': {
- target: process.env.PROXY_URL,
- },
- },
- },
- optimization: {
- minimize: isEnvProduction,
- minimizer: [
- new TerserPlugin({
- terserOptions: {
- parse: {
- ecma: 8,
- },
- warnings: false,
- compress: {
- ecma: 5,
- warnings: false,
- comparisons: false,
- inline: 2,
- },
- mangle: true,
- output: {
- ecma: 5,
- comments: false,
- ascii_only: true,
- },
- },
- parallel: true,
- cache: true,
- sourceMap: true,
- }),
- ],
- splitChunks: {
- chunks: 'all',
- },
- },
- devtool: isEnvProduction ? 'source-map' : 'eval-cheap-module-source-map',
- performance: false,
- plugins: [
- new DefinePlugin({
- 'process.env': JSON.stringify(dotEnv.parsed),
- }),
- new HtmlWebpackPlugin({
- template: './src/index.html',
- filename: './index.html',
- favicon: './src/assets/images/favicon.ico',
- showErrors: true,
- inject: true,
- }),
- new CleanWebpackPlugin(),
- new MiniCssExtractPlugin({
- filename: '[name].[hash:10].css',
- }),
- ],
- };
Advertisement
Add Comment
Please, Sign In to add comment