-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
executable file
·143 lines (128 loc) · 3.56 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
const path = require( 'path' );
const webpack = require( 'webpack' );
const nodeExternals = require( 'webpack-node-externals' );
const CleanWebpackPlugin = require( 'clean-webpack-plugin' );
const HtmlWebpackPlugin = require( 'html-webpack-plugin' );
const DEV_MODE = process.env.NODE_ENV !== 'production';
const ROOT_DIR = path.resolve( __dirname, '.' ); // .. when we get into it
const resolvePath = ( ...args ) => path.resolve( ROOT_DIR, ...args );
const SRC_DIR = resolvePath( 'src' );
const BUILD_DIR = resolvePath( 'dist' );
const entryConfig_client = [
'@babel/polyfill',
DEV_MODE ? 'webpack-hot-middleware/client?name=client&reload=true&path=/__webpack_hmr' : null,
path.resolve( path.join( __dirname, 'client.js' ) ),
].filter( Boolean );
const moduleConfig_client = {
rules: [ {
test: /\.css$/,
use: ['style-loader', 'css-loader']
}, {
test: /\.(mjs|jsx?)$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
cacheDirectory: true,
}
}
}, {
test: /\.(woff(2)?|ttf|eot|svg)(\?v=\d+\.\d+\.\d+)?$/,
use: {
loader: 'file-loader',
options: {
name: '[name].[ext]',
}
}
} ]
};
const pluginsConfig_client = [
new webpack.DefinePlugin( {
__DEV__: DEV_MODE,
'process.env.BROWSER': true,
'process.env.NODE_ENV': DEV_MODE ? '"development"' : '"production"'
} ),
new HtmlWebpackPlugin({
title: 'PDF Analysis'
}),
DEV_MODE ? new webpack.HotModuleReplacementPlugin() : null,
DEV_MODE ? null : new CleanWebpackPlugin( [ BUILD_DIR ] ),
].filter( Boolean );
const clientConfig = {
name: 'client',
target: 'web',
mode: DEV_MODE ? "development" : "production",
entry: entryConfig_client,
module: moduleConfig_client,
plugins: pluginsConfig_client,
output: {
path: BUILD_DIR,
filename: '[name].bundle.js',
publicPath: "/"
},
resolve: {
modules: [
SRC_DIR,
resolvePath( 'node_modules' )
]
},
};
// /*
const entryConfig_server = [
'@babel/polyfill',
DEV_MODE ? 'webpack-hot-middleware/client?name=server&reload=true' : null,
path.resolve( path.join( __dirname, 'server.js' ) ),
].filter( Boolean );
const moduleConfig_server = {
rules: [ {
test: /\.(mjs|jsx?)$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
cacheDirectory: true,
}
}
} ]
};
const pluginsConfig_server = [
new webpack.DefinePlugin( {
__DEV__: DEV_MODE,
'process.env.BROWSER': false,
'process.env.NODE_ENV': DEV_MODE ? '"development"' : '"production"'
} ),
DEV_MODE ? new webpack.HotModuleReplacementPlugin() : null,
DEV_MODE ? null : new CleanWebpackPlugin( [ path.resolve(SRC_DIR, '*.bundle.js') ] ),
].filter( Boolean );
const serverConfig = {
name: 'server',
target: 'node',
mode: DEV_MODE ? "development" : "production",
entry: entryConfig_server,
module: moduleConfig_server,
plugins: pluginsConfig_server,
output: {
path: SRC_DIR,
filename: 'server.bundle.js',
},
watch: DEV_MODE,
resolve: {
modules: [
SRC_DIR,
resolvePath( 'node_modules' )
]
},
externals: [ nodeExternals( { // i think we want to explictly exclude assets?
whitelist: [] // i think we /want/ to include static files under node_modules?
} ) ],
node: {
console: false,
global: false,
process: false,
Buffer: false,
__filename: false,
__dirname: false,
},
};
// */
module.exports = [clientConfig, serverConfig];