-
Notifications
You must be signed in to change notification settings - Fork 8
/
webpack.config.js
67 lines (54 loc) · 1.54 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
/* eslint-env node */
const { lstatSync, readdirSync } = require('fs');
const { resolve, basename } = 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) => resolve(source, name))
.filter((s) => lstatSync(s).isDirectory());
const exampleDirs = getDirectories(src);
return exampleDirs.reduce((entry, dir) => {
entry['./' + basename(dir) + '/bundle'] = `${dir}/index`;
return entry;
}, {});
};
module.exports = {
entry: generateExampleEntries(),
mode: 'development',
output: {
path: resolve(__dirname, 'dist'),
publicPath: '/',
// [name] here will be used from the "entry" object.
// As each key in "entry" object forms a file path,
// Webpack will create a matching folder structure
// on build.
filename: '[name].js',
},
module: {
rules: [
{
test: /\.(t|j)sx?$/,
loader: 'babel-loader',
options: {
presets: [['@babel/preset-env', { targets: { chrome: '60' } }]],
},
},
],
},
resolve: {
extensions: ['.ts', '.tsx', '.js', '.json'],
alias: {
'react-magnetic-di': resolve(__dirname, './src'),
},
},
devServer: {
static: resolve(__dirname, 'examples'),
// hot: true,
},
};