generated from yarindeoh/create-react-app-light
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathwebpack.config.js
128 lines (125 loc) · 4.2 KB
/
webpack.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
'use strict';
const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const dotenv = require('dotenv');
const fs = require('fs');
const SitemapPlugin = require('sitemap-webpack-plugin').default;
const paths = [
{
path: '',
lastmod: '2020-11-24T12:37:09+00:00',
priority: 0.8,
changefreq: 'weekly'
},
{
path: '/addStory/',
lastmod: '2021-02-28',
priority: 0.5,
changefreq: 'monthly'
},
{
path: '/pages/warning-signs/',
lastmod: '2021-02-15',
priority: 0.5,
changefreq: 'monthly'
},
{
path: '/pages/about/',
lastmod: '2021-01-23',
priority: 0.2,
changefreq: 'monthly'
},
{
path: '/pages/terms-of-service/',
lastmod: '2021-01-21',
priority: 0.2,
changefreq: 'monthly'
}
];
module.exports = (env, argv) => {
// Get the root path (assuming your webpack config is in the root of your project!)
const currentPath = path.join(__dirname);
// Create the fallback path (the production .env)
const basePath = currentPath + '/.env';
// We're concatenating the environment name to our filename to specify the correct env file!
const envPath = basePath + '.' + env.ENVIRONMENT;
// Check if the file exists, otherwise fall back to the production .env
const finalPath = fs.existsSync(envPath) ? envPath : basePath;
// Set the path parameter in the dotenv config
const fileEnv = dotenv.config({ path: finalPath }).parsed;
// reduce it to a nice object, the same as before (but with the variables from the file)
const envKeys = Object.keys(fileEnv).reduce((prev, next) => {
prev[`process.env.${next}`] = JSON.stringify(fileEnv[next]);
return prev;
}, {});
return {
performance: { hints: false },
entry: path.resolve(__dirname, 'src/index.js'),
devtool: argv.mode === 'development' ? 'inline-source-map' : 'none',
resolve: {
extensions: ['jsx', '.js'],
alias: {
resources: path.resolve(__dirname, 'resources'),
src: path.resolve(__dirname, 'src'),
components: path.resolve(__dirname, 'src/components'),
services: path.resolve(__dirname, 'src/services'),
media: path.resolve(__dirname, 'src/media'),
containers: path.resolve(__dirname, 'src/containers')
}
},
output: {
filename: 'bundle.js',
path: path.resolve('build'),
publicPath: '/'
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader',
},
{
test: /\.(css|scss)$/,
loaders: ['style-loader', 'css-loader', 'sass-loader'],
include: path.resolve(__dirname, '../')
},
{
test: /\.(svg)$/,
use: ['@svgr/webpack']
},
{
test: /\.(jpg|png|gif|ico|ttf|woff|woff2|eot)(\?.*)?$/,
use: [
{
loader: 'file-loader',
options: {
name: '[path][name].[ext]',
output: {
path: path.join(__dirname, 'build')
}
}
}
]
}
]
},
devServer: {
port: 9000,
hot: true,
historyApiFallback: true,
proxy: {
'/api': 'localhost:5000'
}
},
plugins: [
new webpack.DefinePlugin(envKeys),
new HtmlWebpackPlugin({
filename: 'index.html',
template: path.resolve(__dirname, 'index.html')
}),
new SitemapPlugin({ base: 'https://hayti-sham.co.il', paths })
]
};
};