-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
79 lines (66 loc) · 1.55 KB
/
index.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
'use strict';
// Modules:
var path = require('path');
var webpack = require('webpack');
var webpackStream = require('webpack-stream');
var WebpackServer = require('webpack-dev-server');
var WebpackLivereload = require('webpack-livereload-plugin');
module.exports = {
config: config,
server: server,
webpack: function (options) {
return webpackStream(config(options));
}
};
// Webpack Config:
function config (options) {
// Default options:
var options = options || {};
options.entry = options.entry || {
app: [options.src || './src/index.js']
};
var loaders = [
{
test: /\.js$/,
loader: 'babel',
exclude: /node_modules/,
query: {
cacheDirectory: true,
presets: ['es2015']
}
}
].concat(options.loaders || []);
// Webpack config:
var config = {
watch: true,
devtool: 'source-map',
entry: options.entry,
output: {
path: options.dest,
publicPath: '/build/',
filename: '[name]-bundle.js'
},
plugins: [
new WebpackLivereload()
],
module: {
loaders: loaders
}
};
return config;
};
// Dev server:
function server (options) {
return function () {
// Default options:
options = options || {};
options.port = options.port || 8080;
new WebpackServer(webpack(config(options))).listen(options.port, 'localhost', function (err) {
if (err) {
console.error('no server started');
} else {
console.log('server started on ' + options.port);
}
});
}
}