-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
162 lines (146 loc) · 5.4 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
var path = require('path');
var webpack = require('webpack');
var ComponentResolverPlugin = require('component-resolver-webpack');
var nodeModulesPath = path.join(__dirname, 'node_modules');
var bowerComponentsPath = path.join(__dirname, 'bower_components');
var vendorPath = path.join(__dirname, 'app/vendor');
module.exports = {
resolveLoader: {
root: nodeModulesPath
},
entry: {
app: ['./index.js'],
vendor: [
'angular',
'angular-ui-router',
'angular-aria',
'angular-messages',
'toaster',
'ngAnimate',
'ngResource',
'ui-bootstrap-tpls',
'jquery',
'bootstrap',
'jQueryUi',
'angular-ui-router-extras',
'script!TweenMax'
]
},
externals: {
},
devtool: 'source-map',
context: __dirname + '/app',
output: {
filename: 'bundle.js',
path: './target/js',
publicPath: '/public/js/',
library: 'PW',
libraryTarget: 'umd'
},
module: {
loaders: [
{test: /jquery\.js$/, loader: 'expose?$' },
{
test: /\.js$/,
exclude: /node_modules|bower_components|vendor/,
loader: 'webpack-traceur?runtime=true&sourceMaps&experimental=true!jshint'
},
{test: /[\/\\]angular.min\.js$/, loader: "exports?angular"},
{test: /\.png$/, loader: 'url?mimetype=image/png'},
{test: /\.html$/, loader: 'raw', exclude: /node_modules|bower_components|vendor/},
{test: /\.less$/, loader: "style!css!less"},
{test: /\.css$/, loader: "style!css"},
{test: /\.scss$/, loader: "style!css!sass"},
{
test: /\.(woff|woff2|ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
loader: 'file-loader?name=/res/[name].[ext]?[hash]'
}
],
noParse: [
],
jshint: {
// Display JSHint messages as webpack errors
emitErrors: true,
// fail the build on JSHInt errors
failOnHint: false
}
},
amd: { jQuery: true },
resolve: {
root: [
nodeModulesPath,
bowerComponentsPath,
vendorPath,
__dirname + "/public/ui-assets/style/"
],
alias: {
'style': __dirname + "/public/ui-assets/style/main.scss",
'directive': __dirname + "/app/common/globals/directive.js",
'jquery': 'jquery/dist/jquery.js',
'jQueryUi': 'jquery-ui/jquery-ui.min.js',
'angular': 'angular/angular.min.js',
'angular-aria': 'angular-aria/angular-aria.min.js',
'angular-ui-router': 'angular-ui-router/release/angular-ui-router.min.js',
'angular-ui-router-extras': 'ui-router-extras/release/ct-ui-router-extras.min.js',
'toaster': 'toaster/toaster.min.js',
'ngAnimate': 'angular-animate/angular-animate.min.js',
'ngResource': 'angular-resource/angular-resource.min.js',
'ui-bootstrap-tpls': 'angular-bootstrap/ui-bootstrap-tpls.min.js',
'bootstrap': 'bootstrap/dist/js/bootstrap.min.js',
'TweenMax': __dirname + '/vendor/greensock-js/src/minified/TweenMax.min.js',
'TweenLite': __dirname + '/vendor/greensock-js/src/minified/TweenLite.min.js',
'lodash': 'underscore/underscore-min.js'
},
extensions: ['', '.js']
},
bail: false,
plugins: [
new ModuleReplacementPlugin(),
new webpack.optimize.AggressiveMergingPlugin(),
new webpack.optimize.DedupePlugin(),
new ComponentResolverPlugin(
['js']
),
new webpack.optimize.CommonsChunkPlugin("vendor", "vendor.bundle.js"),
new webpack.ProvidePlugin({
$: "jquery",
jQuery: "jquery",
"window.jQuery": "jquery",
"window.$": "jquery"
})
]
};
function ModuleReplacementPlugin () {
this.resourceRegExp = [];
var filesystem = require("fs");
var modules = filesystem.readdirSync(__dirname + "/app/modules");
for(var module in modules) {
var name = modules[module];
this.resourceRegExp.push(name);
}
}
ModuleReplacementPlugin.prototype.apply = function (compiler) {
var resourceRegExp = this.resourceRegExp;
compiler.plugin("normal-module-factory", function (nmf) {
nmf.plugin("before-resolve", function (result, callback) {
if (!result) {
return callback();
}
var split = result.request.split(".");
if(split.length > 0) {
var name = split[0];
if(resourceRegExp.indexOf(name) > -1 && name != 'bower' && name != 'containers' && name != 'service') {
result.request = __dirname + "/app/modules/" + split.join("/");
} else if(name != 'bower' && name == 'containers') {
var map = split.slice(1);
result.request = __dirname + "/app/containers/" + map.join("/");
} else if(name == 'bower') {
var map = split.slice(1);
result.request = bower_dir + "/" + map.join("/");
}
return callback(null, result);
}
return callback(result, result);
});
});
};