-
Notifications
You must be signed in to change notification settings - Fork 149
/
webpack.config.js
executable file
·98 lines (88 loc) · 2.47 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
/* eslint-disable */
var path = require('path');
var fs = require('fs');
var webpack = require('webpack');
var HtmlWebpackPlugin = require('html-webpack-plugin');
var postNested = require('postcss-nested');
var cssnext = require('cssnext');
var TARGET = process.env.npm_lifecycle_event;
var EXAMPLES_DIR = path.resolve(__dirname, 'examples');
const ROOT_PATH = process.cwd();
module.exports = {
entry: buildEntries(),
output: {
path: ROOT_PATH + '/examples/__build__',
publicPath: '/',
filename: '[name].js',
chunkFilename: '[name].chunk.min.js',
},
devtool: 'eval-source-map',
devServer: {
historyApiFallback: true,
disableHostCheck: true,
hot: true,
inline: true,
host: '0.0.0.0',
},
resolve: {
extensions: ['.json', '.js', '.jsx', '.css'],
},
resolveLoader: {
moduleExtensions: ['-loader'],
},
performance: {
hints: false,
},
module: {
rules: [
{
test: /\.jsx?$/,
loader: 'babel',
exclude: /node_modules/,
},
{
test: /\.css$/,
use: [
{loader: 'style'},
{loader: 'css'},
{
loader: 'postcss',
options: {config: {path: path.join(__dirname, 'postcss.config.js')}},
},
],
},
],
},
plugins: [
new HtmlWebpackPlugin({
title: 'lib-temlate',
template: 'examples/index.html', // Load a custom template
inject: 'body', // Inject all scripts into the body
}),
new webpack.DefinePlugin({
'process.env.NODE_ENV': '"development"',
}),
new webpack.HotModuleReplacementPlugin(),
new webpack.optimize.CommonsChunkPlugin({
name: [
'vendor',
], // vendor libs + extracted manifest
minChunks: Infinity
}),
],
};
function buildEntries() {
return fs.readdirSync(EXAMPLES_DIR).reduce(function(a, b) {
if (b === '__build__') {
return a;
}
var isDraft = b.charAt(0) === '_';
if (!isDraft && isDirectory(path.join(EXAMPLES_DIR, b))) {
a[b] = path.join(EXAMPLES_DIR, b, 'index.js');
}
return a;
}, {});
}
function isDirectory(dir) {
return fs.lstatSync(dir).isDirectory();
}