-
Notifications
You must be signed in to change notification settings - Fork 2
/
webpack.backend.config.js
74 lines (70 loc) · 1.69 KB
/
webpack.backend.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
const CleanWebpackPlugin = require('clean-webpack-plugin');
const nodeExternals = require('webpack-node-externals');
const webpack = require('webpack');
const path = require('path');
const fs = require('fs');
const {
__PROD__,
__DEV__,
frontendBuiltPath,
backendBuiltPath,
srcPath,
frontendSrcPath,
backendSrcPath,
endpoint,
} = require('./environment');
const compact = arr => arr.filter(v => v !== false);
const babel = {
loader: 'babel-loader',
options: {
retainLines: true,
cacheDirectory: __DEV__,
},
};
const alias = {
'/environment': path.resolve(__dirname, 'environment.js'),
};
fs.readdirSync(backendSrcPath).forEach(name => {
alias['/' + name] = path.resolve(backendSrcPath, name);
});
module.exports = {
name: 'backend',
target: 'node',
node: {
__dirname: true,
},
devtool: __DEV__ && 'inline-eval-cheap-source-map',
externals: [nodeExternals()],
entry: backendSrcPath,
resolve: {
modules: [backendSrcPath],
extensions: ['.js'],
alias,
},
output: {
filename: 'index.js',
path: backendBuiltPath,
publicPath: endpoint,
library: 'backend',
libraryTarget: 'umd',
},
plugins: __DEV__ ? [
new webpack.DefinePlugin({ 'process.env.NODE_ENV': "'development'" }),
new webpack.HotModuleReplacementPlugin(),
new webpack.NoEmitOnErrorsPlugin(),
new webpack.NamedModulesPlugin(),
] : [
new CleanWebpackPlugin([backendBuiltPath]),
new webpack.DefinePlugin({ 'process.env.NODE_ENV': "'production'" }),
new webpack.optimize.MinChunkSizePlugin({ minChunkSize: 10000 }),
],
module: {
rules: [
{
test: /\.js$/,
include: srcPath,
loaders: [babel],
},
],
},
};