forked from mongo-express/mongo-express
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
103 lines (90 loc) · 2.93 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
import { createRequire } from 'node:module';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import AssetsPlugin from 'assets-webpack-plugin';
import { CleanWebpackPlugin } from 'clean-webpack-plugin';
import CopyWebpackPlugin from 'copy-webpack-plugin';
import webpack from 'webpack';
const require = createRequire(import.meta.url);
const env = process.env.NODE_ENV || 'development';
const isDev = env === 'development';
const isProd = !isDev;
const fileSuffix = isDev ? '' : '-[chunkhash].min';
function resolveModulePath(name) {
return path.dirname(require.resolve(`${name}/package.json`));
}
const codemirrorPath = resolveModulePath('codemirror');
const bootstrapPath = resolveModulePath('bootstrap');
export default {
mode: isProd ? 'production' : 'development',
performance: {
maxEntrypointSize: 768000,
maxAssetSize: 768000,
},
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: fileURLToPath(new URL('build', import.meta.url)),
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),
};