-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
104 lines (99 loc) · 3.38 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
const path = require('path')
const webpack = require('webpack')
const { CleanWebpackPlugin } = require('clean-webpack-plugin')
const nodeExternals = require('webpack-node-externals')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const mode = (process.env.NODE_ENV === 'dev') ? 'development' : 'production'
const LoadablePlugin = require('@loadable/webpack-plugin')
const { I18NextHMRPlugin } = require('i18next-hmr/plugin')
/* GENERAL config */
var config = {
mode: mode,
module: {
rules: [
{
test: /\.jsx?$/,
exclude: /node_modules/,
use: ['babel-loader'] },
{ test: /\.s[ac]ss$/,
use: [ 'css-loader', 'sass-loader' ] },
{ test: /\.css$/,
use: [ 'css-loader' ] },
{ test: /\.(png|jpe?g|gif|ico|svg)$/i,
exclude: [/node_modules/],
use: [ {
loader: 'file-loader',
options: {
name: '[name].[ext]',
publicPath: '/img',
outputPath: 'img'
}
} ],
},
{
test: /\.json$/,
exclude: [/node_modules/],
loader: 'file-loader',
type: 'javascript/auto',
options: {
name: '[folder]/[name].[ext]',
publicPath: '/locales',
outputPath: 'locales'
}
},
{ test: /\.(woff(2)?|ttf|eot|svg)(\?v=\d+\.\d+\.\d+)?$/,
exclude: [/img/],
use: [
{
loader: 'file-loader',
options: {
name: '[name].[ext]',
publicPath: '/fonts',
outputPath: 'fonts'
}
} ],
}
]
},
plugins: [
new LoadablePlugin(),
new webpack.ProvidePlugin({ process: ['process'] }),
new webpack.NoEmitOnErrorsPlugin(),
new MiniCssExtractPlugin({
filename: (mode === 'production') ? 'css/[contentHash].css' : 'css/[id].css',
chunkFilename: (mode === 'production') ? 'css/[contentHash].css' : 'css/[id].css'
}),
new I18NextHMRPlugin({
localesDir: path.resolve(__dirname, 'locales'),
})
],
}
/* Frontend (client browser with React.js) side config */
const clientConfig = Object.assign({}, config, {
name: "clientReact",
target: "web",
entry: {
client: [ './frontend/client.js' ],
},
resolve: {
fallback: { "crypto": require.resolve("crypto-browserify") }
},
output: {
path: path.resolve(__dirname, 'build/public/'),
filename: (mode === 'production') ? 'js/[chunkhash].js' : 'js/[name].js',
publicPath: '/build/public/',
},
})
/* Backend (server with Express.js) side config */
const serverConfig = Object.assign({}, config, {
name: "serverExpress",
target: "node",
entry: { server: './backend/server.js' },
output: {
path: path.resolve(__dirname, 'build/'),
filename: (mode === 'production') ? 'js/[chunkhash].js' : 'js/[name].js',
publicPath: '/build/',
},
externals: [ nodeExternals() ]
})
module.exports = [ serverConfig, clientConfig ]