This repository has been archived by the owner on May 4, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
163 lines (159 loc) · 5.68 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
154
155
156
157
158
159
160
161
162
163
'use strict';
var webpack = require('webpack');
var AsyncUglifyJs = require("async-uglify-js-webpack-plugin");
var path = require('path');
var CompressionPlugin = require('compression-webpack-plugin');
var root = __dirname + '/';
var srcRoot = root + 'src/';
var npmRoot = root + 'node_modules/';
var stylesRoot = srcRoot + 'styles/';
var nodeScripts = root + 'node_modules/';
var scripts = srcRoot + 'scripts/';
var buildScripts = root + 'src/scripts/';
var releaseScripts = 'build/release/';
var vendorScripts = buildScripts + 'vendor/';
var vendorStyles = stylesRoot + 'vendor/';
var appScripts = buildScripts + 'app/';
var componentScripts = buildScripts + 'app/components/';
var modelScripts = buildScripts + 'app/models/';
var serviceScripts = buildScripts + 'app/services/';
var config = {
cache: false,
entry: [
'./src/scripts/app/main.jsx'
],
output: {
path: path.join(__dirname, 'dist'),
filename: 'bundle.js',
sourceMapFilename: 'bundle.js.map',
publicPath: '/static/'
},
module: {
/*preLoaders: [
{
test: /\.js$/,
exclude: [/node_modules/, /vendor/],
loader: "jshint-loader"
}
],
jshint: {
esnext: true,
failOnHint: false
},*/
loaders: [
{
include: /\.json$/,
loaders: ["json-loader"]
},
{
test : /\.ts$/,
exclude: [/^(node_modules|bower_components|vendor)/],
loader: 'typescript-loader?typescriptCompiler=typescript'
},
{
test : /\.(es6|js|jsx)$/,
exclude: [/^(node_modules|bower_components|vendor)/],
loader: 'babel-loader',
query: {
presets: ['stage-0', 'stage-1', 'stage-2', 'es2015']
}
},
{
test : /\.html$/,
loader: 'html'
},
{
test : /\.scss$/,
loader: 'style-loader!css-loader!scss-loader'
},
{
test : /\.less$/,
loader: 'style-loader!css-loader!less-loader'
},
{
test : /\.css$/,
loader: 'style-loader!css-loader'
},
{ test: /.(png|woff(2)?|eot|ttf|svg)(\?[a-z0-9=\.]+)?$/,
loader: 'url-loader?limit=8192'
},
{ test: /\.jpg$/,
loader: "file-loader?name=[path][name].[ext]"
},
]
},
resolve: {
// root: root,
extensions: ['.js', '.es6', '.es6.js', '.jsx', '.json', '.ts', '.css', '.html'],
// modulesDirectories: ['node_modules', 'bower_components', 'vendorStyles', 'vendorScripts'],
alias: {
"bootstrap.css" : "static/styles/bootstrap/css/bootstrap.min.css",
"bootstrap-theme.css" : "static/styles/bootstrap/css/bootstrap-theme.min.css",
"bootstrap.js" : "src/scripts/vendor/bootstrap/js/bootstrap.min.js"
}
},
plugins: [
/* new CompressionPlugin({
asset : '{file}.gz',
algorithm : 'gzip',
regExp : /\.js$|\.html$/,
threshold : 10240,
minRatio : 0.8
}),*/
//
// new webpack.HotModuleReplacementPlugin(),
new webpack.ProvidePlugin({
$: "jquery",
jQuery: "jquery",
"windows.jQuery": "jquery",
'fetch': 'imports?this=>global!exports?global.fetch!whatwg-fetch'
})
]
};
if (process.env.NODE_ENV === 'production') {
config.plugins = config.plugins.concat([
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify('production')
}
}),
new webpack.optimize.LimitChunkCountPlugin({ maxChunks: 1 }),
new AsyncUglifyJs({
delay: 5000,
minifyOptions: {
mangle: false,
warnings: true,
compress: {
sequences : true, // join consecutive statemets with the “comma operator”
properties : true, // optimize property access: a["foo"] → a.foo
dead_code : true, // discard unreachable code
drop_debugger : true, // discard “debugger” statements
unsafe : false, // some unsafe optimizations (see below)
conditionals : true, // optimize if-s and conditional expressions
comparisons : true, // optimize comparisons
evaluate : true, // evaluate constant expressions
booleans : true, // optimize boolean expressions
loops : true, // optimize loops
unused : true, // drop unused variables/functions
hoist_funs : true, // hoist function declarations
hoist_vars : false, // hoist variable declarations
if_return : true, // optimize if-s followed by return/continue
join_vars : true, // join var declarations
cascade : true, // try to cascade `right` into `left` in sequences
side_effects : true, // drop side-effect-free statements
warnings : true, // warn about potentially dangerous optimizations/code
}
},
logger: false,
done: function(path, originalContents) { }
}),
new webpack.optimize.DedupePlugin(),
new webpack.optimize.OccurenceOrderPlugin(true)
]);
} else {
config.devtool = '#source-map';
// config.debug = true;
}
// config.useMemoryFs = true;
// config.progress = true;
module.exports = config;