-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwebpack.config.js
126 lines (114 loc) · 2.88 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
const webpack = require('webpack');
const path = require('path');
const fs = require('fs');
const env = require('yargs').argv.env.mode;
const target = require('yargs').argv.env.target;
const UglifyPlugin = webpack.optimize.UglifyJsPlugin;
const CommonsChunkPlugin = webpack.optimize.CommonsChunkPlugin;
const HtmlWebpackPlugin = require('html-webpack-plugin');
const BrowserSyncPlugin = require('browser-sync-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const WebpackOnBuildPlugin = require('on-build-webpack');
const nodeModulesDir = path.resolve(__dirname, './node_modules');
let outputFile = `.bundle`;
let outputPath;
const plugins = [];
const nodeModules = {};
const config = {
entry_point: 'http://localhost:8999',
app_id: 'healthy-weight',
}
// uglify
if (env === 'production') {
plugins.push(new UglifyPlugin({
output: {
comments: false,
},
minimize: true,
sourceMap: false,
compress: {
warnings: false,
}
}));
outputFile = `${outputFile}.min.js`;
outputPath = `${__dirname}/dist/`;
} else {
outputFile = `${outputFile}.js`;
outputPath = `${__dirname}/dist/`;
devtool = 'source-map';
}
// livereload
plugins.push(new BrowserSyncPlugin({
proxy: {
target: config.entry_point,
},
port: 9000,
open: false,
logLevel: 'debug',
}, {
reload: false,
}));
plugins.push(new CopyWebpackPlugin([{
from: './app/favicon.ico',
to: 'favicon.ico',
}]));
// healthy-weight
plugins.push(new HtmlWebpackPlugin({
template: './app/index.html',
inject: 'body',
chunks: ['vendors', 'app', 'style'],
hash: true,
}));
// launch
plugins.push(new HtmlWebpackPlugin({
template: './app/launch/index.html',
filename: 'launch/index.html',
inject: 'body',
chunks: ['vendors', 'launch', 'launchStyle'],
hash: true,
}));
const webpackConfig = {
entry: {
app: `${__dirname}/app/healthy-weight.js`,
style: `${__dirname}/app/healthy-weight.css`,
launch: `${__dirname}/app/launch/launch.js`,
launchStyle: `${__dirname}/app/launch/launch.css`,
vendors: `${__dirname}/app/vendors.js`,
},
output: {
path: outputPath,
filename: '[name]' + outputFile,
},
module: {
loaders: [{
test: /\.jsx?$/,
loader: 'babel-loader',
exclude: /node_modules/,
query: {
presets: ['es2015'],
cacheDirectory: true
}
}, {
test: /\.css$/,
loader: 'style-loader!css-loader'
}, {
test: /\.(png|jpg|jpeg|gif|svg)$/,
loader: 'url'
}, {
test: /\.html$/,
loader: 'html-loader'
}, {
test: [/MaterialIcons-Regular.eot/, /MaterialIcons-Regular.woff2/, /MaterialIcons-Regular.woff/, /MaterialIcons-Regular.ttf/],
loader: 'file?name=fonts/[name].[ext]'
}],
},
resolve: {
extensions: ['.js', '.css', '.html'],
},
plugins,
externals: nodeModules,
devServer: {
inline: true,
},
}
module.exports = webpackConfig;