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
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 @@ ...@@ -24,7 +24,14 @@
const CheckPortPlugin = require("./plugins/check-port"); const CheckPortPlugin = require("./plugins/check-port");
const BuildFolderWiper = require("./plugins/build-wiper"); 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 @@ ...@@ -33,7 +40,7 @@
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
const requiredFiles = [paths.index_html, paths.index]; const requiredFiles = [indexHtmlPath, entryPointFile];
if (!checkRequiredFiles(requiredFiles)) { if (!checkRequiredFiles(requiredFiles)) {
process.exit(1); process.exit(1);
...@@ -64,5 +71,5 @@ ...@@ -64,5 +71,5 @@
return { return {
target: "web", target: "web",
entry: paths.index, entry: entryPointFile,
output: { output: {
...@@ -68,5 +75,5 @@ ...@@ -68,5 +75,5 @@
output: { output: {
path: paths.build, path: buildDir,
filename: isDevelopment filename: isDevelopment
? "static/js/[name].js" ? "static/js/[name].js"
: isProduction && "static/js/[name].[contenthash:8].js", : isProduction && "static/js/[name].[contenthash:8].js",
...@@ -152,5 +159,5 @@ ...@@ -152,5 +159,5 @@
}, },
resolve: { resolve: {
extensions: ["*", ".js", ".ts", ".tsx"], extensions: ["*", ".js", ".ts", ".tsx"],
modules: [paths.src, paths.modules], modules: [sourcesDir, nodeModulesDir],
fallback: { fallback: {
...@@ -156,5 +163,5 @@ ...@@ -156,5 +163,5 @@
fallback: { fallback: {
contentBase: paths.build, contentBase: buildDir,
events: false, events: false,
url: false, url: false,
}, },
...@@ -162,7 +169,7 @@ ...@@ -162,7 +169,7 @@
plugins: [ plugins: [
new ESLintPlugin({ formatter: eslintFormatter }), new ESLintPlugin({ formatter: eslintFormatter }),
new HtmlWebpackPlugin({ new HtmlWebpackPlugin({
template: paths.index_html, template: indexHtmlPath,
}), }),
isProduction && isProduction &&
new MiniCssExtractPlugin({ new MiniCssExtractPlugin({
...@@ -191,9 +198,9 @@ ...@@ -191,9 +198,9 @@
new CopyWebpackPlugin({ new CopyWebpackPlugin({
patterns: [ patterns: [
{ {
from: paths.public, from: publicDir,
to: ".", to: ".",
}, },
], ],
}), }),
isDevelopment && new CheckPortPlugin(port), isDevelopment && new CheckPortPlugin(port),
...@@ -195,9 +202,9 @@ ...@@ -195,9 +202,9 @@
to: ".", to: ".",
}, },
], ],
}), }),
isDevelopment && new CheckPortPlugin(port), isDevelopment && new CheckPortPlugin(port),
isProduction && new BuildFolderWiper(paths.build), isProduction && new BuildFolderWiper(buildDir),
new webpack.DefinePlugin({ new webpack.DefinePlugin({
"process.env.NODE_ENV": JSON.stringify(webpackEnv.mode), "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