-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathwebpack.config.js
153 lines (147 loc) · 4.79 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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
const Path = require('path');
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const Webpack = require("webpack");
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const NgAnnotatePlugin = require('ng-annotate-webpack-plugin');
/**
* Utils
*/
const removeEmpty = arr => arr.filter((p) => !!p);
/**
* Path and env configs
*/
const PATHS = {
app: Path.join(__dirname, 'src'),
dev: Path.resolve(__dirname, 'public'),
build: Path.join(__dirname, 'dist'),
test: Path.join(__dirname, 'test'),
vendors: /node_modules|bower_components/
};
process.traceDeprecation = true;
module.exports = env => ({
devtool: 'hidden',
entry: Path.resolve(__dirname, PATHS.app + '/main.js'),
output: {
filename: '[name].bundle.js',
path: Path.resolve(__dirname, PATHS.dev),
sourceMapFilename: '[name].map'
},
devServer: {
contentBase: PATHS.dev,
compress: true,
port: 9001,
proxy: {
"/socket.io": "http://localhost:6040",
"/api": "http://localhost:6040"
}
},
resolve: {
alias: {
sigma: Path.resolve(__dirname, "node_modules/sigma/build/sigma.require.js")
}
},
plugins: removeEmpty([
new BundleAnalyzerPlugin({
openAnalyzer: false,
analyzerMode: 'static'
}),
new Webpack.optimize.UglifyJsPlugin({
sourceMap: false,
mangle: false
}),
new Webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
chunks: ['main'],
minChunks: module => PATHS.vendors.test(module.resource)
}),
new Webpack.ProvidePlugin({
app: `exports?exports.default!${Path.join(PATHS.app, 'app')}`,
$: Path.resolve(__dirname, "node_modules/jquery/dist/jquery.min.js"),
}),
new Webpack.ContextReplacementPlugin(/moment[\/\\]locale$/, /en/),
new NgAnnotatePlugin({
add: true,
// other ng-annotate options here
}),
]),
module: {
rules: [
{
test: /\.js$/,
exclude: PATHS.vendors,
use: [{
loader: 'babel-loader',
options: {
presets: ['react', 'es2015']
}
}/* , {
loader: 'ng-annotate-loader',
options: {
add: true,
map: false,
}
} */]
}, {
test: /\.scss$/,
loader: 'style!css!scss',
include: PATHS.app,
}, {
test: /\.css$/,
// exclude: PATHS.vendors,
use: ["style-loader", 'css-loader']
}, {
test: /\.html$/,
exclude: /node_modules/,
use: [{
loader: 'html-loader',
options: {
minimize: true,
},
}],
}, {
test: /\.(ttf|otf|eot|svg|woff(2)?)(\?[a-z0-9]+)?$/,
loader: 'file-loader?name=fonts/[name].[ext]'
}, {
test: /\.(swf)$/,
loader: 'file-loader?name=[name].[ext]'
}, {
test: /\.(png|jpg|gif|svg)$/,
use: [{
loader: 'file-loader',
options: {
query: {
name:'img/[name].[ext]'
}
}
},
{
loader: 'image-webpack-loader',
options: {
query: {
mozjpeg: {
progressive: true,
},
gifsicle: {
interlaced: true,
},
optipng: {
optimizationLevel: 7,
}
}
}
}]
}, {
test: /\/sigma.*\.js?$/,
use: [{
loader: 'imports-loader?sigma'
}]
},
/*{
test: /\/sigma.*\.js?$/, // the test to only select sigma files
exclude: ['src'], // you ony need to check node_modules, so remove your application files
loader: 'script-loader' // loading as script
}, */
]
}
});