-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.config.server.babel.js
82 lines (80 loc) · 2.28 KB
/
webpack.config.server.babel.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
import path from 'path'
// import CONFIG from './config/app.config'
import CleanFolder from 'clean-webpack-plugin'
import OptmizeCSS from 'optimize-css-assets-webpack-plugin'
import UglifyJsPlugin from 'uglifyjs-webpack-plugin'
const distPath = 'deploy'
const environment = process.env.NODE_ENV ? process.env.NODE_ENV.trim() : 'development'
export default {
module: {
rules: [
{
test: /\.jsx?$/, // regex to find files that webpack applies
resolve: {
extensions: ['.js', '.jsx', '.styl'], // resolves files extensiosn
},
exclude: /node_modules/, // avoiding node_module folders
use: {
loader: 'babel-loader', // using babel loader for transpiling es6 to es5
options: {
cacheDirectory: true, // option to transpile only modfied files
},
},
},
{
test: /\.(png|svg|jpg|gif)$/,
use: [
{
loader: 'file-loader',
options: {
name: '[name].[ext]',
outputPath: 'img/',
publicPath: '/static/img',
},
},
],
},
],
},
target: 'node',
node: {
__dirname: false, // to fix static files in express
},
performance: {
hints: false,
},
devtool:
environment === 'development'
? 'source-map'
: 'false' /* testing if it's in development mode or production (to generate soucermap file for minified js file) */,
optimization: {
minimizer:
environment === 'production'
? [
new UglifyJsPlugin({
test: /\.js(\?.*)?$/i,
cache: true,
parallel: true,
sourceMap: environment === 'production',
uglifyOptions: {
output: {
comments: false,
},
},
}),
new OptmizeCSS({}),
]
: [],
},
entry: './src/server.js', // main file to generates the bundle
output: {
// output settings
path: path.resolve(__dirname, `${distPath}`), // it defines its output folder
filename: 'server.js', // bundle name
publicPath: '/',
},
plugins: [
// define plugins used by webpack and its properties/settings
new CleanFolder([`${distPath}/server.js`], { root: __dirname }),
],
}