From 426868de202b0f59ef25a845724f126107cfde84 Mon Sep 17 00:00:00 2001 From: "Begerad, Stefan" Date: Wed, 15 Jun 2022 11:06:53 +0200 Subject: [PATCH] feat(webpack-react): mv webpack config to config folder --- webpack-react/{ => config}/webpack.common.js | 8 +++--- webpack-react/{ => config}/webpack.dev.js | 2 +- webpack-react/{ => config}/webpack.prod.js | 0 webpack-react/package.json | 4 +-- webpack-react/src/index.js | 2 +- webpack-react/webpack.config.js | 26 -------------------- 6 files changed, 8 insertions(+), 34 deletions(-) rename webpack-react/{ => config}/webpack.common.js (80%) rename webpack-react/{ => config}/webpack.dev.js (90%) rename webpack-react/{ => config}/webpack.prod.js (100%) delete mode 100644 webpack-react/webpack.config.js diff --git a/webpack-react/webpack.common.js b/webpack-react/config/webpack.common.js similarity index 80% rename from webpack-react/webpack.common.js rename to webpack-react/config/webpack.common.js index 2ea923a..cd6338c 100644 --- a/webpack-react/webpack.common.js +++ b/webpack-react/config/webpack.common.js @@ -4,11 +4,11 @@ const HtmlWebpackPlugin = require('html-webpack-plugin'); const path = require('path'); module.exports = { //bundle *.js from this entry point - entry: path.resolve(__dirname, 'src/index.js'), + entry: path.resolve(__dirname, '../src/index.js'), //create output file to be linked to index.html output: { filename: '[name].bundle.js', - path: path.resolve(__dirname, './dist'), + path: path.resolve(__dirname, '../dist'), clean: true, }, module: { @@ -18,7 +18,7 @@ module.exports = { //test all *.jsx (e.g. React.js) using babel-loader test: /\.(js|jsx)$/, exclude: /node_modules/, - include: path.resolve(__dirname, 'src'), + include: path.resolve(__dirname, '../src'), use: ['babel-loader'], } ] @@ -30,7 +30,7 @@ module.exports = { // create an plugin instance so that you can use it several times anywhere new HtmlWebpackPlugin({ title: 'Production', - template: path.resolve(__dirname, "public/index.html") + template: path.resolve(__dirname, "../public/index.html") }), ], }; diff --git a/webpack-react/webpack.dev.js b/webpack-react/config/webpack.dev.js similarity index 90% rename from webpack-react/webpack.dev.js rename to webpack-react/config/webpack.dev.js index b96558f..844d354 100644 --- a/webpack-react/webpack.dev.js +++ b/webpack-react/config/webpack.dev.js @@ -9,6 +9,6 @@ module.exports = merge(common, { //enable strong source mapping devtool: 'inline-source-map', devServer: { - static: path.resolve(__dirname, 'dist'), + static: path.resolve(__dirname, '../dist'), }, }); diff --git a/webpack-react/webpack.prod.js b/webpack-react/config/webpack.prod.js similarity index 100% rename from webpack-react/webpack.prod.js rename to webpack-react/config/webpack.prod.js diff --git a/webpack-react/package.json b/webpack-react/package.json index 204587d..b30f418 100644 --- a/webpack-react/package.json +++ b/webpack-react/package.json @@ -14,8 +14,8 @@ "node": ">=10" }, "scripts": { - "start": "webpack serve --open --config webpack.dev.js", - "build": "webpack --config webpack.prod.js" + "start": "webpack serve --open --config config/webpack.dev.js", + "build": "webpack --config config/webpack.prod.js" }, "devDependencies": { "@babel/core": "^7.18.2", diff --git a/webpack-react/src/index.js b/webpack-react/src/index.js index eee756b..2c507a4 100644 --- a/webpack-react/src/index.js +++ b/webpack-react/src/index.js @@ -3,7 +3,7 @@ import ReactDOM from 'react-dom'; import Home from './pages/home'; //TODO remove debugging if (process.env.NODE_ENV !== 'production') { - console.log('development mode!'); + console.log('development mode'); } //since react 18 import { createRoot } from 'react-dom/client'; diff --git a/webpack-react/webpack.config.js b/webpack-react/webpack.config.js deleted file mode 100644 index eda630f..0000000 --- a/webpack-react/webpack.config.js +++ /dev/null @@ -1,26 +0,0 @@ -//path is used to resolve properly across the OS -const path = require('path'); - -module.exports = { - //bundle *.js from this entry point - entry: path.resolve(__dirname, './src/index.js'), - module: { - rules: [ - { - //test all *.js using babel-loader - //test all *.jsx (e.g. React.js) using babel-loader - test: /\.(js|jsx)$/, - exclude: /node_modules/, - use: ['babel-loader'], - } - ] - }, - resolve: { - extensions: ['*', '.js', '.jsx'], - }, - //create output file to be linked to index.html - output: { - path: path.resolve(__dirname, './public'), - filename: 'bundle.js', - }, -};