-
Notifications
You must be signed in to change notification settings - Fork 2
/
webpack.js
126 lines (113 loc) · 4.03 KB
/
webpack.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
var fs = require("fs");
var path = require('path');
var webpack = require('webpack');
var srcDir = path.join(__dirname, 'website');
var targetDir = path.join(__dirname, '_target');
var HandlebarsPlugin = require("handlebars-webpack-plugin");
var ExtractTextPlugin = require("extract-text-webpack-plugin");
var DirectoryNameAsMain = require('webpack-directory-name-as-main');
var config = {
entry: {
main: path.join(srcDir, 'main.js')
},
plugins: [
new HandlebarsPlugin({
// path to hbs entry file(s)
entry: path.join(srcDir, "*.hbs"),
// output path and filename(s). This should lie within the webpacks output-folder
// if ommited, the input filepath stripped of its extension will be used
output: path.join(targetDir, "[name].html"),
// data passed to main hbs template: `main-template(data)`
data: require(path.join(srcDir, "data.json")),
// hooks
onBeforeSetup: function (Handlebars) {},
onBeforeAddPartials: function (Handlebars, partialsMap) {},
onBeforeCompile: function (Handlebars, templateContent) {},
onBeforeRender: function (Handlebars, data) {},
onBeforeSave: function (Handlebars, resultHtml, filename) {},
onDone: function (Handlebars, filename) {}
}),
new ExtractTextPlugin("assets/[name].css"),
new webpack.ResolverPlugin([
new DirectoryNameAsMain()
]),
new webpack.ProvidePlugin({
$: "jquery",
jQuery: "jquery",
"window.jQuery": "jquery"
})
],
output: {
path: targetDir,
filename: "assets/[name].js"
},
resolve: {
root: path.resolve(srcDir),
modulesDirectories: [
path.join(__dirname, 'node_modules')
],
extensions: ['', '.js'],
alias: {
'babel-polyfill': path.join(__dirname, 'babel-polyfill/dist/polyfill.js')
}
},
module: {
loaders: [
{
test: /\.js$/,
exclude: /(node_modules)/,
loader: 'babel-loader',
query: {
presets: ["es2015"]
}
},
{
test: /\.scss$/,
loader: ExtractTextPlugin.extract(
'style',
`css!autoprefixer-loader?{browsers:["last 2 versions","> 5%"]}!sass-loader?includePaths[]=` + path.resolve(__dirname, "./node_modules/compass-mixins/lib")
)
},
{
test: /\.less$/,
loader: ExtractTextPlugin.extract(
'style',
`css!autoprefixer-loader?{browsers:["last 2 versions","> 5%"]}!less`
)
},
{
test: /\.css$/,
loader: ExtractTextPlugin.extract("style-loader", "css-loader")
},
{ test: /\.(jpg|png|gif)$/, loader: "file-loader?name=images/[name].[md5:hash:base58:8].[ext]" },
{ test: /\.(woff|woff2)(\?v=[0-9]\.[0-9]\.[0-9]+)?$/, loader: "url-loader?limit=10000&minetype=application/font-woff&name=fonts/[name].[md5:hash:base58:8].[ext]" },
{ test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9]+)?$/, loader: "file-loader?name=fonts/[name].[md5:hash:base58:8].[ext]" }
]
}
};
var watch = process.argv.indexOf('--watch') >= 0;
var minimize = process.argv.indexOf('--minimize') >= 0;
var compiler = webpack(config);
minimize && config.plugins.push(new webpack.optimize.UglifyJsPlugin({
mangle: {
except: ['$super', '$', 'exports', 'require']
}
}));
var statOpts = {
hash: true,
timing: true,
assets: true,
chunks: false,
children: false,
version: false
};
if (watch) {
compiler.watch({}, function (err, stats) {
console.log(stats.toString(statOpts));
}
);
} else {
compiler.run(function (err, stats) {
console.log(stats.toString(statOpts));
});
}