-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack-trials.config.js
81 lines (74 loc) · 1.68 KB
/
webpack-trials.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
const path = require('path');
const fs = require('fs');
const RemovePlugin = require('remove-files-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const trialsDir = './trials';
const srcDir = `${trialsDir}/src/`;
const distDir = `${trialsDir}/dist/`;
// getting all .js fileds from srcDir
const files = fs.readdirSync(srcDir);
const entries = files
.filter(f => f.lastIndexOf('.ts') === f.length - 3)
.map(f => f.substr(0, f.length - 3));
// creating a map object of file name to file path
const entry = entries.reduce((acc, filename) => {
acc[filename] = `${srcDir}${filename}.ts`;
return acc;
}, {});
// creating an HTMLPlugin for each entry
const htmlPlugins = entries.map(
filename =>
new HtmlWebpackPlugin({
inject: true,
template: `${srcDir}_template.html`,
chunks: [filename],
filename: `${filename}.html`,
})
);
module.exports = {
mode: 'development',
//entry: './src/index.ts',
entry,
devtool: 'inline-source-map',
/*
output: {
libraryTarget: 'commonjs',
filename: 'bundle.js',
path: path.resolve(__dirname, 'dist'),
},
*/
output: {
path: path.resolve(__dirname, distDir),
filename: '[name].js',
},
resolve: {
alias: {
src: path.resolve(__dirname, 'src/'),
},
extensions: ['.tsx', '.ts', '.js'],
},
module: {
rules: [
{
test: /\.tsx?$/,
use: [{ loader: 'babel-loader' }, { loader: 'ts-loader' }],
exclude: /node-modules/,
},
],
},
plugins: [
/*
new RemovePlugin({
before: {
include: [distDir],
// parameters for "before normal compilation" stage.
},
watch: {
include: [distDir],
// parameters for "before watch compilation" stage.
},
}),
*/
...htmlPlugins,
],
};