-
-
Notifications
You must be signed in to change notification settings - Fork 391
/
webpack.config.babel.js
107 lines (100 loc) · 2.32 KB
/
webpack.config.babel.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
import path from 'path';
import webpack from 'webpack';
import HappyPack from 'happypack';
import DashboardPlugin from 'webpack-dashboard/plugin';
import BabiliPlugin from 'babili-webpack-plugin';
import externals from './tools/externals';
const consoleColors = {
reset: '\x1b[0m',
hicolor: '\x1b[1m',
underline: '\x1b[4m',
inverse: '\x1b[7m',
// foreground colors
black: '\x1b[30m',
red: '\x1b[31m',
green: '\x1b[32m',
yellow: '\x1b[33m',
blue: '\x1b[34m',
magenta: '\x1b[35m',
cyan: '\x1b[36m',
white: '\x1b[37m'
};
const log = (color, msg) => console.log(consoleColors[color], msg, consoleColors.reset);
export function config(
{
isProduction,
isMinified = false,
src,
dest,
filename = 'whs.js',
plugins = [],
version = require('./package.json').version
}
) {
if (process.env.CI) isProduction = true;
log('red', `Mode: ${isProduction ? 'production' : 'development'}`);
log('magenta', `Version: ${version}`);
const bannerText = `WhitestormJS Framework v${version}`;
return {
devtool: isProduction ? 'source-map' : 'cheap-module-eval-source-map',
cache: true,
entry: [
`${src}/index.js`
],
target: 'web',
output: {
path: path.join(__dirname, dest),
filename,
library: 'WHS',
libraryTarget: 'umd'
},
module: {
rules: [
{
test: /\.js$/,
exclude: [
/node_modules/
],
loader: 'babel-loader', // babel-loader
query: {
cacheDirectory: true
}
}
]
},
externals: {
three: externals.three
},
plugins: [
new webpack.LoaderOptionsPlugin({
minimize: isProduction,
debug: !isProduction
}),
...(isProduction ? [
...(isMinified ? [
new BabiliPlugin({
mangle: true
}, {
sourceMap: true
})
] : [])
] : [
new DashboardPlugin()
]),
new HappyPack({loaders: ['babel-loader'], threads: 4}),
new webpack.BannerPlugin(bannerText),
...plugins
],
resolve: {
modules: [
path.resolve(__dirname, 'node_modules'),
src
]
}
};
}
export default () => config({
isProduction: process.env.NODE_ENV === 'production',
src: './src',
dest: './build'
});