forked from mongo-express/mongo-express
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
99 lines (85 loc) · 2.78 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
'use strict';
const webpack = require('webpack');
const path = require('path');
const AssetsPlugin = require('assets-webpack-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const env = process.env.NODE_ENV || 'development';
const isDev = env === 'development';
const isProd = !isDev;
const fileSuffix = isDev ? '' : '-[chunkhash].min';
function resolveModulePath(name) {
const packageJson = '/package.json';
return path.dirname(require.resolve(`${name}${packageJson}`));
}
const codemirrorPath = resolveModulePath('codemirror');
const bootstrapPath = resolveModulePath('bootstrap');
module.exports = {
mode: isProd ? 'production' : 'development',
entry: {
index: {
import: './lib/scripts/index.js',
dependOn: 'vendor',
},
database: {
import: './lib/scripts/database.js',
dependOn: 'vendor',
},
collection: {
import: './lib/scripts/collection.js',
dependOn: ['vendor', 'codemirror'],
},
document: {
import: './lib/scripts/document.js',
dependOn: ['vendor', 'codemirror'],
},
gridfs: {
import: './lib/scripts/gridfs.js',
dependOn: 'vendor',
},
// Shared
vendor: './lib/scripts/vendor.js',
codemirror: {
import: './lib/scripts/codeMirrorLoader.js',
dependOn: 'vendor',
},
},
output: {
filename: `[name]${fileSuffix}.js`,
path: path.join(__dirname, 'build'),
publicPath: 'public/',
},
module: {
rules: [
{
test: /.js$/,
loader: 'babel-loader',
exclude: /(node_modules)/,
options: {
presets: ['@babel/preset-env'],
},
},
],
},
plugins: [
new CleanWebpackPlugin(),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(env),
__DEV__: isDev,
}),
new CopyWebpackPlugin({
patterns: [
{ from: 'public/images/*', to: 'img/[name][ext]' },
{ from: 'public/stylesheets/*', to: 'css/[name][ext]' },
{ from: path.join(codemirrorPath, '/lib/codemirror.css'), to: 'css/[name][ext]' },
{ from: path.join(codemirrorPath, '/theme/*'), to: 'css/theme/[name][ext]' },
{ from: path.join(bootstrapPath, '/dist/fonts/*'), to: 'fonts/[name][ext]' },
{ from: path.join(bootstrapPath, '/dist/css/bootstrap.min.css'), to: 'css/[name][ext]' },
{ from: path.join(bootstrapPath, '/dist/css/bootstrap.min.css.map'), to: 'css/[name][ext]' },
{ from: path.join(bootstrapPath, '/dist/css/bootstrap-theme.min.css'), to: 'css/[name][ext]' },
{ from: path.join(bootstrapPath, '/dist/css/bootstrap-theme.min.css.map'), to: 'css/[name][ext]' },
],
}),
new AssetsPlugin({ filename: 'build-assets.json' }),
].filter((n) => !!n),
};