-
Notifications
You must be signed in to change notification settings - Fork 28
/
webpack.config.js
65 lines (53 loc) · 1.42 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
const { lstatSync, readdirSync } = require('fs');
const path = require('path');
// This function generates configuration for files in the
// ./src/examples/ folder
const generateExampleEntries = function () {
const src = './examples';
// Get all subdirectories in the ./src/apps,
// so we can just add a new folder there and
// have automatically the entry points updated
const getDirectories = source =>
readdirSync(source)
.map(name => path.resolve(source, name))
.filter(s => lstatSync(s).isDirectory());
const exampleDirs = getDirectories(src);
return exampleDirs.reduce((entry, dir) => {
entry['./' + path.basename(dir) + '/bundle'] = `${dir}/index`;
return entry;
}, {});
};
module.exports = {
mode: 'development',
entry: generateExampleEntries(),
devServer: {
static: {
directory: path.resolve(__dirname, 'examples'),
publicPath: '/',
},
},
output: {
filename: '[name].js',
path: path.resolve(__dirname, 'dist'),
},
module: {
rules: [
{
test: /\.(t|j)sx?$/,
loader: 'babel-loader',
options: {
presets: [
['@babel/preset-env', { targets: { chrome: '60' } }],
'@babel/preset-typescript',
],
},
},
],
},
resolve: {
alias: {
'react-resource-router': path.resolve(__dirname, './src'),
},
extensions: ['.ts', '.tsx', '.js', '.json'],
},
};