guild_front/config/webpack/common.js

137 lines
2.9 KiB
JavaScript
Raw Permalink Normal View History

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