forked from microsoft/frontend-bootcamp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
127 lines (119 loc) · 3.15 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
const path = require('path');
const fs = require('fs');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const outPath = path.resolve(__dirname, 'docs');
const entries = {};
const nonWebpackedEntries = [];
function* getEntryPoint(step) {
if (step.includes('step') || step.includes('playground')) {
for (let prefix of ['', 'demo/', 'exercise/', 'final/']) {
for (let suffix of ['.js', '.jsx', '.ts', '.tsx']) {
const entryRequest = `./${step}/${prefix}src/index${suffix}`;
if (fs.existsSync(entryRequest)) {
yield entryRequest;
}
}
}
}
return false;
}
fs.readdirSync('./').filter(step => {
let isEntryPoint = false;
for (let entryPoint of getEntryPoint(step)) {
if (entryPoint) {
entries[entryPoint.replace(/\/src\/index.*/, '').replace(/^\.\//, '')] = entryPoint;
isEntryPoint = true;
}
}
if (!isEntryPoint && step.includes('step')) {
nonWebpackedEntries.push(step);
}
});
module.exports = function(env, argv) {
return {
entry: { ...entries, markdownReadme: './markdownReadme/src/index.ts' },
module: {
rules: [
{
test: /\.tsx?$/,
use: {
loader: 'ts-loader',
options: {
transpileOnly: true
}
},
exclude: /node_modules/
},
{
test: /\.css$/,
use: ['style-loader', 'css-loader'],
exclude: /node_modules/
}
]
},
plugins: [
...Object.keys(entries).map(entry => {
return new HtmlWebpackPlugin({
template: path.join(__dirname, entry, 'index.html'),
filename: `${entry}/index.html`,
chunks: [entry, 'markdownReadme']
});
}),
new CopyWebpackPlugin([
...Object.keys(entries).map(entry => {
return {
from: `${entry}/src/**/*`,
to: outPath
};
}),
...Object.keys(entries).map(entry => {
return {
from: `${entry}/../*.+(md|html)`,
to: outPath
};
}),
...Object.keys(entries).map(entry => {
return {
from: `${entry}/*.+(md|html)`,
to: outPath
};
}),
{
from: 'assets/**/*',
to: outPath
},
{
from: 'index.html',
to: outPath
},
...nonWebpackedEntries.map(entry => ({ from: `${entry}/**/*`, to: outPath }))
]),
new ForkTsCheckerWebpackPlugin({
silent: true,
async: false
})
],
resolve: {
extensions: ['.tsx', '.ts', '.js']
},
output: {
filename: '[name]/[name].js',
path: outPath
},
devServer: {
contentBase: path.resolve(__dirname),
watchContentBase: true,
watchOptions: {
ignored: /tmp.json/
},
hot: false,
stats: 'errors-only',
overlay: true,
inline: true
},
stats: 'minimal',
devtool: argv.mode === 'development' ? 'eval' : 'source-map'
};
};