Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const path = require('path');
- const webpack = require('webpack');
- const merge = require('webpack-merge');
- const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
- const HtmlWebpackPlugin = require('html-webpack-plugin');
- const MiniCssExtractPlugin = require('mini-css-extract-plugin');
- const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
- const FaviconsWebpackPlugin = require('favicons-webpack-plugin');
- const isProduction = process.env.NODE_ENV === 'production';
- const common = {
- target: 'web',
- entry: {
- main: path.resolve(__dirname, 'src', 'index.jsx'),
- },
- output: {
- path: path.resolve(__dirname, 'dist'),
- filename: isProduction ? '[name].[chunkhash].js' : '[name].js',
- publicPath: '/',
- },
- module: {
- rules: [
- {
- test: /\.jsx?$/,
- exclude: /node_modules(?!\/astralnalog)/,
- use: ['babel-loader?cacheDirectory=true'],
- },
- {
- test: /\.s?[ac]ss$/,
- use: [MiniCssExtractPlugin.loader, 'css-loader', 'postcss-loader', 'sass-loader'],
- },
- {
- test: /\.(png|svg|jpg|gif)$/,
- use: ['file-loader'],
- },
- {
- test: /\.(woff|woff2|eot|ttf|otf)$/,
- use: ['file-loader'],
- },
- {
- test: /\.(pdf)$/,
- use: ['file-loader?minetype=application/pdf'],
- },
- ],
- },
- plugins: [
- new webpack.DefinePlugin({
- 'process.env': {
- NODE_ENV: JSON.stringify(process.env.NODE_ENV),
- },
- }),
- new HtmlWebpackPlugin({
- inject: false,
- cache: true,
- minify: isProduction,
- template: path.join('src', 'index.html'),
- title: 'Title',
- }),
- new MiniCssExtractPlugin({
- filename: isProduction ? '[name].[contenthash].css' : '[name].css',
- chunkFilename: isProduction ? '[name].[contenthash].chunk.css' : '[name].chunk.css',
- }),
- ],
- resolve: {
- extensions: ['.js', '.jsx', '.css', '.scss'],
- },
- devServer: {
- stats: 'minimal',
- historyApiFallback: true,
- contentBase: path.resolve(__dirname, 'dist'),
- proxy: {
- '/api': 'http://localhost:5000',
- '/api/hub': {
- ws: true,
- target: 'ws://localhost:5000/',
- },
- },
- },
- };
- module.exports = isProduction
- ? merge(common, {
- plugins: [
- new webpack.HashedModuleIdsPlugin(),
- new FaviconsWebpackPlugin('./src/favicon.svg'),
- ],
- optimization: {
- minimize: true,
- occurrenceOrder: true,
- runtimeChunk: true,
- splitChunks: {
- cacheGroups: {
- commons: {
- test: /[\\/]node_modules[\\/]/,
- name: 'vendors',
- chunks: 'all',
- },
- },
- },
- minimizer: [
- new UglifyJsPlugin({
- cache: true,
- parallel: true,
- uglifyOptions: {
- compress: {
- drop_console: true,
- },
- dead_code: true,
- },
- }),
- new OptimizeCSSAssetsPlugin({
- cssProcessorOptions: {
- discardUnused: { fontFace: false },
- discardComments: { removeAll: true },
- },
- }),
- ],
- },
- })
- : merge(common, {
- devtool: 'cheap-module-source-map',
- plugins: [new webpack.NamedModulesPlugin()],
- });
Add Comment
Please, Sign In to add comment