Skip to content
Snippets Groups Projects
Commit 36d075346b34 authored by Frank Bessou's avatar Frank Bessou :spider_web:
Browse files

refactor(webpack): remove paths.js file and rename its exported variables

parent dd0211bc8300
No related branches found
No related tags found
1 merge request!1Many little improvements
This commit is part of merge request !1. Comments created here will be created in the context of that merge request.
const path = require("path");
//------------------------------------------------------------------------------
const rootDir = path.resolve(__dirname, "../");
module.exports = {
modules: path.resolve(path.join(rootDir, "node_modules")),
public: path.resolve(path.join(rootDir, "src/assets/public")),
src: path.resolve(path.join(rootDir, "src")),
build: path.resolve(path.join(rootDir, "build")),
index: path.resolve(path.join(rootDir, "src/index.tsx")),
index_html: path.resolve(path.join(rootDir, "index.html")),
};
......@@ -24,7 +24,14 @@
const CheckPortPlugin = require("./plugins/check-port");
const BuildFolderWiper = require("./plugins/build-wiper");
const paths = require("./paths");
const rootDir = path.resolve(__dirname, "../");
const nodeModulesDir = path.join(rootDir, "node_modules");
const publicDir = path.join(rootDir, "src/assets/public");
const sourcesDir = path.join(rootDir, "src");
const buildDir = path.join(rootDir, "build");
const indexHtmlPath = path.join(rootDir, "index.html");
const entryPointFile = path.join(rootDir, "src/index.tsx");
//------------------------------------------------------------------------------
......@@ -33,7 +40,7 @@
//------------------------------------------------------------------------------
const requiredFiles = [paths.index_html, paths.index];
const requiredFiles = [indexHtmlPath, entryPointFile];
if (!checkRequiredFiles(requiredFiles)) {
process.exit(1);
......@@ -64,5 +71,5 @@
return {
target: "web",
entry: paths.index,
entry: entryPointFile,
output: {
......@@ -68,5 +75,5 @@
output: {
path: paths.build,
path: buildDir,
filename: isDevelopment
? "static/js/[name].js"
: isProduction && "static/js/[name].[contenthash:8].js",
......@@ -152,5 +159,5 @@
},
resolve: {
extensions: ["*", ".js", ".ts", ".tsx"],
modules: [paths.src, paths.modules],
modules: [sourcesDir, nodeModulesDir],
fallback: {
......@@ -156,5 +163,5 @@
fallback: {
contentBase: paths.build,
contentBase: buildDir,
events: false,
url: false,
},
......@@ -162,7 +169,7 @@
plugins: [
new ESLintPlugin({ formatter: eslintFormatter }),
new HtmlWebpackPlugin({
template: paths.index_html,
template: indexHtmlPath,
}),
isProduction &&
new MiniCssExtractPlugin({
......@@ -191,9 +198,9 @@
new CopyWebpackPlugin({
patterns: [
{
from: paths.public,
from: publicDir,
to: ".",
},
],
}),
isDevelopment && new CheckPortPlugin(port),
......@@ -195,9 +202,9 @@
to: ".",
},
],
}),
isDevelopment && new CheckPortPlugin(port),
isProduction && new BuildFolderWiper(paths.build),
isProduction && new BuildFolderWiper(buildDir),
new webpack.DefinePlugin({
"process.env.NODE_ENV": JSON.stringify(webpackEnv.mode),
}),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment