-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.js
More file actions
145 lines (136 loc) · 3.95 KB
/
webpack.config.js
File metadata and controls
145 lines (136 loc) · 3.95 KB
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/**
* Created by niko on 21.09.16.
*/
const NODE_ENV = process.env.NODE_ENV || 'development';
const HOST = process.env.HOST || 'localhost';
const PORT = process.env.PORT || '7001';
const webpack = require('webpack');
const rimraf = require('rimraf');
const path = require('path');
const CommonsChunkPlugin = webpack.optimize.CommonsChunkPlugin;
const BowerWebpackPlugin = require('bower-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const DefinePlugin = webpack.DefinePlugin;
const ProvidePlugin = webpack.ProvidePlugin;
const UglifyJsPlugin = webpack.optimize.UglifyJsPlugin;
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
var paths = {
context: path.join(__dirname, 'sources'),
dist: path.join(__dirname, 'dist'),
static: path.join(__dirname, 'static')
};
var webpackConfig = {
context: paths.context,
entry: {
vendor: './vendor',
app: './app'
},
output: {
path: paths.dist,
publicPath: '/',
filename: '[name].bundle.js',
chunkFilename: '[id].chunk.js'
},
resolve: {
modulesDirectories: ['bower_components', 'node_modules'],
extensions: ['', '.js']
},
module: {
loaders: [
{
test: /\.js$/,
exclude: /(bower_components|node_modules)/,
loader: 'ng-annotate!babel'
},
{
test: /angular\.js$/,
loader: 'exports?angular'
},
{
test: /\.html$/,
loader: 'html'
},
{
test: /\.json$/,
loader: 'json'
},
{
test: /\.css$/,
loader: ExtractTextPlugin.extract('style', 'css')
},
{
test: /\.less$/,
loader: ExtractTextPlugin.extract('style', 'css!less')
},
{
test: /\.(png|jpe|gif|svg|woff|ttf|eot|ico)([?]?.*)$/,
include: /(bower_components|node_modules)/,
loader: 'url?name=[1][name].[ext]&limit=524288®Exp=(bower_components|node_modules)/(.*)'
},
{
test: /\.(png|jpe|gif|svg|woff|ttf|eot|ico)([?]?.*)$/,
exclude: /(bower_components|node_modules)/,
loader: 'url?name=[path][name].[ext]&limit=524288'
}
],
noParse: [
/socket.io-client/,
]
},
plugins: [
{
apply: (compiler) => (rimraf.sync(compiler.options.output.path))
},
new CommonsChunkPlugin({
name: ['app', 'vendor'],
minChunks: 2
}),
new BowerWebpackPlugin({
includes: /\.(js|css)/
}),
new HtmlWebpackPlugin({
template: path.join(paths.context, 'index.html')
}),
new DefinePlugin({
'process.env': {
'NODE_ENV': JSON.stringify(NODE_ENV),
'HOST': JSON.stringify(HOST)
}
}),
new ProvidePlugin({
$: 'jquery',
jQuery: 'jquery',
'window.jQuery': 'jquery'
}),
new ExtractTextPlugin('[name].bundle.css', {
allChunks: true
}),
new CopyWebpackPlugin([
{
from: paths.static
}
])
]
};
if (NODE_ENV == 'development') {
webpackConfig.devServer = {
contentBase: paths.dist,
host: HOST,
port: PORT,
inline: true,
stats: 'minimal',
historyApiFallback: true
};
webpackConfig.devtool = 'source-map';
webpackConfig.watch = true;
}
if (NODE_ENV == 'production') {
webpackConfig.plugins.push(new UglifyJsPlugin({
compress: {
warnings: false,
drop_console: true
}
}));
}
module.exports = webpackConfig;