forked from smallbets/userbase-homepage
/
webpack.config.js
executable file
·156 lines (144 loc) · 4.11 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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
const fs = require('fs')
const path = require('path')
const glob = require('glob')
const webpack = require('webpack')
const TerserPlugin = require('terser-webpack-plugin')
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const HtmlWebPackPlugin = require('html-webpack-plugin')
const HtmlBeautifyPlugin = require('html-beautify-webpack-plugin')
const FaviconsWebpackPlugin = require('favicons-webpack-plugin')
const SocialTags = require('social-tags-webpack-plugin')
const OpenBrowserPlugin = require('opn-browser-webpack-plugin')
module.exports = (env, argv) => {
const pages = []
fs.readdirSync('./src/pages/').forEach(file => {
const page = file.split('.')[0]
let filename = './'
if (page !== 'index') {
const pagePath = page.split('_')
for (let i = 0; i < pagePath.length; i++) {
filename += pagePath[i] + '/'
}
}
filename += 'index.html'
pages.push(new HtmlWebPackPlugin({
template: './src/template.html',
filename,
templateParameters() { return { page } }
}))
})
const config = {
entry: {
main: './src/index.js'
},
output: {
path: path.join(__dirname, 'dist'),
publicPath: '/',
filename: '[name].js',
globalObject: 'this'
},
target: 'web',
devtool: 'source-map',
resolve: {
extensions: ['.js', '.jsx'],
},
performance: {
hints: false
},
module: {
rules: [
{
test: /\.css$/,
use: [
MiniCssExtractPlugin.loader, 'css-loader', 'postcss-loader',
]
},
{
enforce: 'pre',
test: /\.js$/,
use: ['source-map-loader'],
},
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader'
},
{
test: /\.(woff|woff2|eot|ttf|otf|png|svg|jpg|gif)$/,
use: ['file-loader']
}
]
},
plugins: [
new MiniCssExtractPlugin({
filename: 'style.css',
chunkFilename: 'style.css',
ignoreOrder: false
}),
...pages,
new FaviconsWebpackPlugin('./src/img/icon.png'),
new SocialTags({
appUrl: 'https://noebs.dev/',
facebook: {
'og:url': "https://noebs.dev",
'og:type': "website",
'og:title': "noebs",
'og:image': './src/img/og_card.jpg',
'og:description': "The easiest and most secure payment integration in Sudan. Start for free and enjoy our seamless payment functionalities!",
'og:site_name': "noebs",
'og:locale': "en_US"
},
twitter: {
"twitter:card": "summary_large_image",
"twitter:site": "@_adonese",
"twitter:creator": "@_adonese",
"twitter:url": "https://noebs.dev",
"twitter:title": "noebs",
"twitter:description": "The easiest and most secure payment integration in Sudan. Start for free and enjoy our seamless payment functionalities!",
"twitter:image": './src/img/og_card.jpg'
},
}),
new HtmlBeautifyPlugin({
config: {
html: {
end_with_newline: true,
indent_size: 2,
indent_with_tabs: false,
indent_inner_html: false,
preserve_newlines: true
}
}
}),
new webpack.NoEmitOnErrorsPlugin(),
new webpack.WatchIgnorePlugin(['./dist'])
]
}
if (argv.mode == 'development') {
config.devtool = 'inline-source-map'
config.devServer = {
watchContentBase: true,
hot: true,
inline: true,
host: '0.0.0.0',
port: 3000
}
config.plugins.push(new webpack.HotModuleReplacementPlugin())
config.plugins.push(new OpenBrowserPlugin({
url: 'http://localhost:3000'
}))
}
if (argv.mode == 'production') {
config.optimization = {
minimizer: [
new TerserPlugin({
cache: true,
parallel: true,
sourceMap: true
}),
new OptimizeCSSAssetsPlugin({})
]
}
}
return config
}