-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebpack.config.js
125 lines (105 loc) · 2.83 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
var path = require('path');
var pkg = require('./package.json');
var webpack = require("webpack");
var HtmlWebpackPlugin = require('html-webpack-plugin');
var util = require('./config/util/');
var loadersByExtension = util.loadersByExtension;
var libPath = path.join(__dirname, 'lib');
var wwwPath = path.join(__dirname, 'www');
var deepExtend = require('deep-extend');
module.exports = function (options) {
'use strict';
var entry = path.join(libPath, 'index.js')
var root = [libPath,];
// Plug-ins
var plugins = [
new HtmlWebpackPlugin({
filename: 'index.html',
pkg: pkg,
template: path.join(libPath, 'index.html')
}),
new webpack.ProvidePlugin({
register: 'registerjs',
_: 'lodash',
}),
];
// Extend default Env with specific env
var env = (require('./env/default.env.json'))
var myenv = (require('./env/' + options.env + '.env.json'))
deepExtend(env, myenv)
plugins.push(
new webpack.DefinePlugin({
Env: JSON.stringify(env)
})
);
// Loaders
var scriptLoaders = {
'js': {
loader: 'ng-annotate?add=true!babel',
exclude: /(node_modules)/,
},
'html': {
loader: 'html'
},
'json': {
loader: "json"
},
'png|jpg|svg': {
loader: 'file?name=images/[path][name].[ext]'
},
'eot|ttf|woff|svg': {
loader: 'file?name=fonts/[name].[ext]'
}
};
var browsers = {browsers: ['last 2 version', 'ie >= 10']};
var stylesheetLoaders = {
'scss|css': 'style!css-loader!autoprefixer-loader?' + JSON.stringify(browsers) + '!sass'
};
Object.keys(stylesheetLoaders).forEach(function (ext) {
var loaders = stylesheetLoaders[ext];
if (Array.isArray(loaders)) loaders = loaders.join('!');
stylesheetLoaders[ext] = 'style-loader!' + loaders;
});
var loaders = loadersByExtension(scriptLoaders).concat(loadersByExtension(stylesheetLoaders));
if (options.optimized) {
plugins.push(
new HtmlWebpackPlugin({
filename: 'index.html',
pkg: pkg,
template: path.join(libPath, 'index.html')
}),
new webpack.ProvidePlugin({
register: 'registerjs'
}),
new webpack.optimize.OccurenceOrderPlugin(),
new webpack.optimize.DedupePlugin(),
new webpack.optimize.UglifyJsPlugin()
)
}
var output = {
path: wwwPath,
filename: 'app-[hash:6].js',
pathinfo: options.debug,
sourceMapFilename: 'debugging/[file].map',
};
// Export
return {
entry: entry,
output: output,
module: {
loaders: loaders,
},
devtool: options.devtool,
resolve: {
extensions: ['', '.js', '.json', '.scss', '.html'],
root: root,
moduleDirectories: [
'node_modules'
],
alias: {
'registerjs': path.resolve(__dirname, './lib/util/register.js'),
}
},
plugins: plugins
}
}