2023-05-24 13:49:09 +03:00
|
|
|
const paths = require("../paths");
|
2023-01-20 16:20:06 +03:00
|
|
|
|
2023-05-24 13:49:09 +03:00
|
|
|
const webpack = require("webpack");
|
2023-01-20 16:20:06 +03:00
|
|
|
|
2023-05-24 13:49:09 +03:00
|
|
|
const CopyWebpackPlugin = require("copy-webpack-plugin");
|
|
|
|
const HtmlWebpackPlugin = require("html-webpack-plugin");
|
2023-01-20 16:20:06 +03:00
|
|
|
|
2023-05-24 13:49:09 +03:00
|
|
|
const Dotenv = require("dotenv-webpack");
|
2023-01-20 16:20:06 +03:00
|
|
|
|
|
|
|
const plugins = [
|
2023-05-24 13:49:09 +03:00
|
|
|
"@babel/plugin-proposal-class-properties",
|
|
|
|
"@babel/plugin-syntax-dynamic-import",
|
|
|
|
"@babel/plugin-transform-runtime",
|
2023-01-20 16:20:06 +03:00
|
|
|
];
|
|
|
|
|
2023-05-24 13:49:09 +03:00
|
|
|
if (process.env.NODE_ENV === "development") {
|
|
|
|
plugins.push("react-refresh/babel");
|
2023-01-20 16:20:06 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
const babelLoader = {
|
2023-05-24 13:49:09 +03:00
|
|
|
loader: "babel-loader",
|
2023-01-20 16:20:06 +03:00
|
|
|
options: {
|
|
|
|
presets: [
|
|
|
|
// "react-app",
|
2023-05-24 13:49:09 +03:00
|
|
|
"@babel/preset-env",
|
|
|
|
"@babel/preset-react",
|
2023-01-20 16:20:06 +03:00
|
|
|
],
|
2023-05-24 13:49:09 +03:00
|
|
|
plugins: plugins,
|
|
|
|
},
|
2023-01-20 16:20:06 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
entry: `${paths.src}/index.js`,
|
|
|
|
output: {
|
|
|
|
path: paths.build,
|
2023-05-24 13:49:09 +03:00
|
|
|
filename: "[name].bundle.js",
|
|
|
|
publicPath: "/",
|
2023-01-20 16:20:06 +03:00
|
|
|
// publicPath: 'https://itguild.info',
|
|
|
|
asyncChunks: true,
|
|
|
|
clean: true,
|
2023-05-24 13:49:09 +03:00
|
|
|
crossOriginLoading: "anonymous",
|
2023-01-20 16:20:06 +03:00
|
|
|
module: true,
|
|
|
|
environment: {
|
|
|
|
arrowFunction: true,
|
|
|
|
bigIntLiteral: false,
|
|
|
|
const: true,
|
|
|
|
destructuring: true,
|
|
|
|
dynamicImport: false,
|
2023-05-24 13:49:09 +03:00
|
|
|
forOf: true,
|
|
|
|
},
|
2023-01-20 16:20:06 +03:00
|
|
|
},
|
|
|
|
resolve: {
|
|
|
|
alias: {
|
2023-05-24 13:49:09 +03:00
|
|
|
"@": `${paths.src}/modules`,
|
2023-05-30 08:05:03 +03:00
|
|
|
assets: `${paths.src}/assets`,
|
|
|
|
"@components": `${paths.src}/components`,
|
2023-05-30 10:10:34 +03:00
|
|
|
"@utils": `${paths.src}/utils`,
|
2023-05-30 08:05:03 +03:00
|
|
|
"@pages": `${paths.src}/pages`,
|
|
|
|
"@redux": `${paths.src}/redux`,
|
|
|
|
"@store": `${paths.src}/store`,
|
|
|
|
"@api": `${paths.src}/api`,
|
|
|
|
"@hooks": `${paths.src}/hooks`,
|
2023-01-20 16:20:06 +03:00
|
|
|
},
|
2023-05-30 08:05:03 +03:00
|
|
|
// extensions: [".mjs", ".js", ".jsx", ".ts", ".tsx", ".json"],
|
|
|
|
extensions: [".jsx", "..."],
|
2023-01-20 16:20:06 +03:00
|
|
|
},
|
|
|
|
experiments: {
|
|
|
|
topLevelAwait: true,
|
2023-05-24 13:49:09 +03:00
|
|
|
outputModule: true,
|
2023-01-20 16:20:06 +03:00
|
|
|
},
|
|
|
|
module: {
|
|
|
|
rules: [
|
|
|
|
// JavaScript, React
|
|
|
|
{
|
|
|
|
test: /\.m?jsx?$/i,
|
|
|
|
exclude: /node_modules/,
|
2023-05-24 13:49:09 +03:00
|
|
|
use: babelLoader,
|
2023-01-20 16:20:06 +03:00
|
|
|
},
|
|
|
|
// TypeScript
|
|
|
|
{
|
|
|
|
test: /.tsx?$/i,
|
|
|
|
exclude: /node_modules/,
|
2023-05-24 13:49:09 +03:00
|
|
|
use: [babelLoader, "ts-loader"],
|
2023-01-20 16:20:06 +03:00
|
|
|
},
|
|
|
|
// CSS, SASS
|
|
|
|
{
|
|
|
|
test: /\.(c|sa|sc)ss$/i,
|
|
|
|
use: [
|
2023-05-24 13:49:09 +03:00
|
|
|
"style-loader",
|
2023-01-20 16:20:06 +03:00
|
|
|
{
|
2023-05-24 13:49:09 +03:00
|
|
|
loader: "css-loader",
|
|
|
|
options: { importLoaders: 1 },
|
2023-01-20 16:20:06 +03:00
|
|
|
},
|
2023-05-24 13:49:09 +03:00
|
|
|
"sass-loader",
|
|
|
|
],
|
2023-01-20 16:20:06 +03:00
|
|
|
},
|
|
|
|
// MD
|
|
|
|
{
|
|
|
|
test: /\.md$/i,
|
2023-05-24 13:49:09 +03:00
|
|
|
use: ["html-loader", "markdown-loader"],
|
2023-01-20 16:20:06 +03:00
|
|
|
},
|
|
|
|
// static files
|
|
|
|
{
|
2023-05-24 13:49:09 +03:00
|
|
|
test: /\.(jpe?g|png|gif|webp|svg|eot|ttf|woff2|woff?)$/i,
|
|
|
|
type: "asset/resource",
|
|
|
|
},
|
|
|
|
],
|
2023-01-20 16:20:06 +03:00
|
|
|
},
|
|
|
|
plugins: [
|
|
|
|
new webpack.ProgressPlugin(),
|
|
|
|
|
|
|
|
new CopyWebpackPlugin({
|
|
|
|
patterns: [
|
|
|
|
{
|
|
|
|
from: `${paths.public}`,
|
|
|
|
globOptions: {
|
2023-05-24 13:49:09 +03:00
|
|
|
ignore: ["**/index.html"],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
2023-01-20 16:20:06 +03:00
|
|
|
}),
|
|
|
|
|
|
|
|
new HtmlWebpackPlugin({
|
|
|
|
template: `${paths.public}/index.html`,
|
|
|
|
// filename: 'index.html',
|
|
|
|
}),
|
|
|
|
|
|
|
|
new webpack.ProvidePlugin({
|
2023-05-24 13:49:09 +03:00
|
|
|
React: "react",
|
2023-01-20 16:20:06 +03:00
|
|
|
}),
|
|
|
|
|
|
|
|
new Dotenv({
|
2023-05-24 13:49:09 +03:00
|
|
|
path: ".env",
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
};
|