-
Notifications
You must be signed in to change notification settings - Fork 52
/
Copy pathwebpack.config.dev.js
91 lines (85 loc) · 2.14 KB
/
webpack.config.dev.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
/* eslint-disable import/no-extraneous-dependencies */
const { readdirSync, statSync } = require('fs');
const { join } = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const configure = require('gda-scripts/config/webpack.configure');
const common = require('ibm-gantt-chart/webpack.common.js');
const pkg = require('./package.json');
// find all subdirectories examples
const getDirectories = p => readdirSync(p).filter(f => statSync(join(p, f)).isDirectory());
const dirs = getDirectories('./src');
const input = {
index: './src/index.js',
};
dirs.forEach(dir => (input[dir] = `./src/${dir}/${dir}.js`));
// generate links for each examples for main page
const bodyHtmlSnippet = `
<h3>${pkg.name}@${pkg.version}</h3>
<ul>
${dirs
.map(
dir => `
<a href="${dir}.html">${dir}</a>
`
)
.join('\n')}
</ul>
`;
const { webpack = {}, styling = {}, html = {}, ...base } = common;
module.exports = configure(pkg, {
// 'print-config': true,
...base,
mode: 'development',
input,
outputName: '[name]',
webpack: {
...webpack,
resolve: {
...(webpack.resolve || {}),
mainFields: ['source'], // use source instead of compiled library
},
plugins: [
...(webpack.plugins || []),
...dirs.map(
dir =>
new HtmlWebpackPlugin({
title: `${dir}`,
filename: `${dir}.html`,
template: `./src/${dir}/${dir}.html`,
chunks: [`${dir}`],
})
),
],
copy: [
...(webpack.copy || []),
{
from: '../ibm-gantt-chart/data',
to: 'data/',
},
{
from: '../../node_modules/jquery/dist',
to: 'jquery/',
},
{
from: '../../node_modules/datatables.net',
to: 'datatables.net/',
},
{
from: '../../node_modules/datatables.net-dt',
to: 'datatables.net-dt/',
},
{
from: '../../node_modules/vis/dist',
to: 'vis/',
},
],
},
styling: {
...styling,
},
html: {
...html,
excludeChunks: dirs.map(dir => `${dir}.js`), // TODO does not work with html-webpack-template
bodyHtmlSnippet,
},
});