Repository navigation
Expand file tree
/
Copy pathwebpack.config.server.js
More file actions
139 lines (135 loc) · 5.45 KB
/
Copy pathwebpack.config.server.js
File metadata and controls
139 lines (135 loc) · 5.45 KB
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
// const reduce = require('lodash/reduce');
const webpack = require('webpack');
const path = require('path');
const fs = require('fs');
const nodeExternals = require('webpack-node-externals');
const GenerateJsonPlugin = require('generate-json-webpack-plugin');
const NodemonPlugin = require('nodemon-webpack-plugin');
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
const SwaggerJSDocWebpackPlugin = require('swagger-jsdoc-webpack-plugin');
const JsDocPlugin = require('jsdoc-webpack-plugin-v2');
// const { StatsWriterPlugin } = require('webpack-stats-plugin');
const CopyPlugin = require('copy-webpack-plugin');
const LoadablePlugin = require('@loadable/webpack-plugin');
const filename = 'server.js';
const cwd = process.cwd();
const json = require(path.resolve(cwd, './package')); // eslint-disable-line
const entry = json.name.includes('webserver') || json.name.includes('docs')
? './index.jsx' : './index.js';
// const alias = reduce(json.dependencies, (acc, v, k) => {
// acc[k] = path.resolve(cwd, 'node_modules', k);
// return acc;
// }, {});
// console.log('alias', alias);
module.exports = (env, argv) => {
const isProd = env ? !!env.prod : false;
// const isDebug = env ? !!env.debug : false;
!isProd && require(path.resolve(cwd, './src/config')); // eslint-disable-line
return {
context: path.resolve(cwd, 'src'),
resolve: {
extensions: ['.json', '.js', '.jsx', '.css', '.scss'],
// alias,
// modules: [path.resolve(cwd), 'node_modules']
},
target: 'node', // in order to ignore built-in modules like path, fs, etc.
externals: [nodeExternals()], // in order to ignore all modules in node_modules folder
devtool: isProd ? '' : 'eval-cheap-module-source-map',
entry,
output: {
path: path.resolve(cwd, 'dist'),
chunkFilename: '[name].js',
filename,
publicPath: '/'
},
mode: isProd ? 'production' : 'development',
module: {
rules: [
{
test: /\.(js|jsx)$/,
use: [
{
loader: 'babel-loader',
options: {
rootMode: 'upward',
}
},
// {
// loader: 'eslint-loader'
// }
],
exclude: /node_modules/,
},
{
test: /\.(css|scss)$/,
use: [
'css-loader',
'sass-loader'
]
},
{
test: /\.(png|jpg|jpeg|gif|ico|svg)$/,
use: [
{
loader: 'file-loader',
options: {}
}
]
}
]
},
plugins: [
new webpack.DefinePlugin({
// 'process.env.PORT': JSON.stringify(process.env.PORT),
// 'process.env.USERS_HOST': JSON.stringify(process.env.USERS_HOST),
// 'process.env.PROJECTS_HOST': JSON.stringify(process.env.PROJECTS_HOST),
// 'process.env.port': JSON.stringify(process.env.port),
// 'process.env.host': JSON.stringify(process.env.host),
// 'process.env.HOST': JSON.stringify(process.env.HOST),
// 'process.env.DEBUG': JSON.stringify(isDebug),
// 'process.env.DEST_PORT': JSON.stringify(process.env.DEST_PORT),
// 'process.env.DOCKER_HOST': JSON.stringify(process.env.DOCKER_HOST),
// 'process.env.DESTINATION_HOST': JSON.stringify(process.env.DESTINATION_HOST)
}),
// new StatsWriterPlugin({
// fields: ["assets", "modules"]
// }),
new LoadablePlugin(),
new GenerateJsonPlugin('package.json', Object.assign({}, json, {
main: filename,
files: [],
scripts: {
start: `node ${filename}`
},
devDependencies: {}
})),
new SwaggerJSDocWebpackPlugin({
swaggerDefinition: {
openapi: '3.0.0',
info: {
title: json.name,
version: json.version,
description: json.description
}
},
apis: ['./src/api/**/index.js', './src/api/**/model.js'],
}),
fs.existsSync(path.resolve(cwd, 'jsdoc.json')) ? new JsDocPlugin({
conf: path.resolve(cwd, 'jsdoc.json') // single jsdoc file
}) : () => {},
// !isProd && process.cwd().includes('webserver1') ? new BundleAnalyzerPlugin({}) : new BundleAnalyzerPlugin({
// analyzerMode: 'static',
// openAnalyzer: false,
//
// }),
new CopyPlugin([
{ from: path.join(cwd, 'app.yml') }
]),
argv.watch ? new NodemonPlugin({
script: path.resolve(cwd, 'dist', filename),
watch: path.resolve(cwd, 'dist', filename),
verbose: true
}) : () => {}
],
};
};