forked from mongo-express/mongo-express
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
85 lines (69 loc) · 2.61 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
'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 = {
entry: {
index: './lib/scripts/index.js',
database: './lib/scripts/database.js',
collection: './lib/scripts/collection.js',
document: './lib/scripts/document.js',
gridfs: './lib/scripts/gridfs.js',
vendor: './lib/scripts/vendor.js',
codemirror: './lib/scripts/codeMirrorLoader.js',
},
output: {
filename: `[name]${fileSuffix}.js`,
path: path.join(__dirname, 'build'),
publicPath: 'public/',
},
module: {
loaders: [
{
test: /.js$/,
loader: 'babel-loader',
exclude: /(node_modules)/,
query: {
presets: ['es2015'],
},
},
],
},
plugins: [
new CleanWebpackPlugin(['build']),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(env),
__DEV__: isDev,
}),
new webpack.optimize.CommonsChunkPlugin({
names: ['codemirror', 'vendor'],
filename: `[name]${fileSuffix}.js`,
}),
isProd && (new webpack.optimize.UglifyJsPlugin()),
isProd && (new webpack.optimize.OccurrenceOrderPlugin(true)),
new CopyWebpackPlugin([
{ 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),
};