commit f902ef2f849c51f41f5c2207cb44a7d95cee7578
parent c61eb2ad77c9c7efd3b898c3d53412b770c9705f
Author: Sergej Orlov <wladimirych@gmail.com>
Date: Sun, 1 Dec 2019 10:05:40 +0100
config: move paths definitions to separate module
Diffstat:
4 files changed, 26 insertions(+), 9 deletions(-)
diff --git a/webpack/paths.js b/webpack/paths.js
@@ -0,0 +1,15 @@
+const path = require('path');
+const fs = require('fs');
+
+function resolveApp(relativePath) {
+ return path.resolve(__dirname, '..', relativePath);
+}
+
+// config after eject: we're in ./config/
+module.exports = {
+ appBuild: resolveApp('build'),
+ appPublic: resolveApp('public'),
+ appIndexJs: resolveApp('src/index.js'),
+ appIndexHtml: resolveApp('src/index.html'),
+ appSrc: resolveApp('src'),
+};
diff --git a/webpack/webpack.common.js b/webpack/webpack.common.js
@@ -1,14 +1,15 @@
-const Path = require('path');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
+const paths = require('./paths');
+
module.exports = {
entry: {
- app: Path.resolve(__dirname, '../src/index.js')
+ app: paths.appIndexJs
},
output: {
- path: Path.join(__dirname, '../build'),
+ path: paths.appBuild,
filename: 'js/[name].js'
},
optimization: {
@@ -20,15 +21,15 @@ module.exports = {
plugins: [
new CleanWebpackPlugin(),
new CopyWebpackPlugin([
- { from: Path.resolve(__dirname, '../public'), to: 'public' }
+ { from: paths.appPublic, to: 'public' }
]),
new HtmlWebpackPlugin({
- template: Path.resolve(__dirname, '../src/index.html')
+ template: paths.appIndexHtml
})
],
resolve: {
alias: {
- '~': Path.resolve(__dirname, '../src')
+ '~': paths.appSrc
}
},
module: {
diff --git a/webpack/webpack.config.dev.js b/webpack/webpack.config.dev.js
@@ -1,6 +1,6 @@
-const Path = require('path');
const Webpack = require('webpack');
const merge = require('webpack-merge');
+const paths = require('./paths');
const common = require('./webpack.common.js');
module.exports = merge(common, {
@@ -21,7 +21,7 @@ module.exports = merge(common, {
rules: [
{
test: /\.js$/,
- include: Path.resolve(__dirname, '../src'),
+ include: paths.appSrc,
enforce: 'pre',
loader: 'eslint-loader',
options: {
@@ -30,7 +30,7 @@ module.exports = merge(common, {
},
{
test: /\.js$/,
- include: Path.resolve(__dirname, '../src'),
+ include: paths.appSrc,
loader: 'babel-loader'
},
{
diff --git a/webpack/webpack.config.prod.js b/webpack/webpack.config.prod.js
@@ -2,6 +2,7 @@ const Webpack = require('webpack');
const merge = require('webpack-merge');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const common = require('./webpack.common.js');
+const paths = require('./paths');
module.exports = merge(common, {
mode: 'production',