-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
106 lines (103 loc) · 2.52 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
const path = require('path');
const fs = require('fs');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const isDirectory = source => fs.lstatSync(source).isDirectory()
const getDirectories = source =>
fs.readdirSync(source).map(name => path.join(source, name)).filter(isDirectory)
const webpackEntries = {};
const webpackPlugins = [];
const paths = {
DIST: path.resolve(__dirname, 'dist'),
SRC: path.resolve(__dirname, 'src'),
JS: path.resolve(__dirname, 'src/js'),
};
// Read configuration files from all example directories
getDirectories('./src').forEach(v => {
const folder = path.basename(v);
if (/^c\d/.test(folder)) {
const [ n, c_no, c_ls ] = folder.match(/c(\d)_(\d+)/);
const conf = require(`./${v}/config.js`);
webpackEntries[folder] = path.join(paths.SRC, `${folder}/app/js/app.js`);
webpackPlugins.push(
new HtmlWebpackPlugin({
hash: true,
title: `Course ${c_no} - Lesson ${c_ls}${conf.title ? ` (${conf.title})` : ''}`,
template: path.join(paths.SRC, `${folder}/index.html`),
filename: path.join(paths.DIST, `${folder}/index.html`),
chunks: [ folder ],
css: [ 'app.css' ],
})
);
}
});
module.exports = {
target: 'web',
entry: {
main: path.join(paths.JS, 'app.js'),
...webpackEntries
},
output: {
path: paths.DIST,
filename: '[name]/app/js/app.js'
},
devServer: {
hot: true,
open: true,
},
plugins: [
new CleanWebpackPlugin(paths.DIST),
new ExtractTextPlugin('style.bundle.css'),
new HtmlWebpackPlugin({
hash: true,
template: path.join(paths.SRC, 'index.html'),
filename: path.join(paths.DIST, 'index.html'),
chunks: [ 'main' ],
}),
...webpackPlugins
],
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: [
'env',
'react',
],
plugins: [
'syntax-class-properties',
'syntax-decorators',
'syntax-object-rest-spread',
'transform-class-properties',
'transform-object-rest-spread'
]
}
}
},
{
test: /\.css$/,
loader: ExtractTextPlugin.extract({
use: 'css-loader',
}),
},
{
test: /\.(png|jpg|gif)$/,
use: [
'file-loader',
],
},
{
test: /\.html/,
use: 'underscore-template-loader'
},
]
},
resolve: {
extensions: ['.js', '.jsx'],
},
};