2020-04-14 10:53:19 +03:00
|
|
|
const webpack = require("webpack");
|
|
|
|
const path = require("path");
|
|
|
|
const HtmlWebpackPlugin = require("html-webpack-plugin");
|
|
|
|
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
|
|
|
|
const webpackBundleAnalyzer = require("webpack-bundle-analyzer");
|
2020-06-07 01:34:52 +03:00
|
|
|
const CopyPlugin = require("copy-webpack-plugin");
|
2021-09-07 19:21:25 +03:00
|
|
|
const config = require("./config");
|
2020-04-14 10:53:19 +03:00
|
|
|
|
2021-09-07 19:21:25 +03:00
|
|
|
process.env.NODE_ENV = config.prod.NODE_ENV;
|
|
|
|
process.env.PUBLIC_URL = config.prod.PUBLIC_URL;
|
|
|
|
|
|
|
|
let configs = {};
|
|
|
|
Object.keys(config.dev).forEach(z => {
|
|
|
|
configs[`process.env.${z}`] = JSON.stringify(config.dev[z]);
|
|
|
|
});
|
2020-04-14 10:53:19 +03:00
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
mode: "production",
|
|
|
|
target: "web",
|
|
|
|
devtool: "source-map",
|
|
|
|
entry: "./src/index",
|
|
|
|
output: {
|
|
|
|
path: path.resolve(__dirname, "build"),
|
2020-05-26 23:58:00 +03:00
|
|
|
publicPath: process.env.PUBLIC_URL,
|
2020-04-14 10:53:19 +03:00
|
|
|
filename: "bundle.js"
|
|
|
|
},
|
|
|
|
plugins: [
|
|
|
|
// Display bundle stats
|
|
|
|
new webpackBundleAnalyzer.BundleAnalyzerPlugin({ analyzerMode: "static" }),
|
|
|
|
|
|
|
|
new MiniCssExtractPlugin({
|
|
|
|
filename: "[name].[contenthash].css"
|
|
|
|
}),
|
|
|
|
|
2021-09-07 19:21:25 +03:00
|
|
|
new webpack.DefinePlugin(configs),
|
2020-04-14 10:53:19 +03:00
|
|
|
new HtmlWebpackPlugin({
|
|
|
|
template: "src/index.html",
|
|
|
|
favicon: "src/favicon.ico",
|
|
|
|
minify: {
|
|
|
|
// see https://github.com/kangax/html-minifier#options-quick-reference
|
|
|
|
removeComments: true,
|
|
|
|
collapseWhitespace: true,
|
|
|
|
removeRedundantAttributes: true,
|
|
|
|
useShortDoctype: true,
|
|
|
|
removeEmptyAttributes: true,
|
|
|
|
removeStyleLinkTypeAttributes: true,
|
|
|
|
keepClosingSlash: true,
|
|
|
|
minifyJS: true,
|
|
|
|
minifyCSS: true,
|
|
|
|
minifyURLs: true
|
|
|
|
}
|
2020-05-27 01:31:31 +03:00
|
|
|
}),
|
|
|
|
new CopyPlugin({
|
2020-06-07 01:34:52 +03:00
|
|
|
patterns: [{ from: "public", to: "public" }]
|
2020-04-14 10:53:19 +03:00
|
|
|
})
|
|
|
|
],
|
|
|
|
module: {
|
|
|
|
rules: [
|
|
|
|
{
|
|
|
|
test: /\.(js|jsx)$/,
|
|
|
|
exclude: /node_modules/,
|
|
|
|
use: ["babel-loader", "eslint-loader"]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
test: /(\.css)$/,
|
|
|
|
use: [
|
|
|
|
MiniCssExtractPlugin.loader,
|
|
|
|
{
|
|
|
|
loader: "css-loader",
|
|
|
|
options: {
|
|
|
|
sourceMap: true
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
loader: "postcss-loader",
|
|
|
|
options: {
|
|
|
|
plugins: () => [require("cssnano")],
|
|
|
|
sourceMap: true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
};
|