-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.config.js
70 lines (67 loc) · 1.55 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
const fs = require('fs')
const path = require('path')
const ESlintPlugin = require('eslint-webpack-plugin')
const { CleanWebpackPlugin } = require('clean-webpack-plugin')
const entrys = {}
const algs4Path = path.resolve(__dirname, 'src/algs4')
function readFileDir(filePath) {
const files = fs.readdirSync(filePath)
for (const fileName of files) {
const fileDir = path.join(filePath, fileName)
const stats = fs.statSync(fileDir)
if (stats.isFile()) {
if (/\.(ts|js)$/.test(fileName)) {
const key = fileName.match(/(^[\w-]{1,})(?=\.(ts|js))/ig)
key && key.length && (entrys[key[0]] = fileDir)
}
}
if (stats.isDirectory()) {
readFileDir(fileDir)
}
}
}
readFileDir(algs4Path)
module.exports = {
target: 'node',
mode: 'development',
entry: {
index: './src/index.ts',
...entrys
},
module: {
rules: [
{
test: /\.m?js$/,
use: 'babel-loader',
exclude: /node_modules/
},
{
test: /\.ts$/,
use: 'ts-loader',
exclude: /node_modules/
}
]
},
resolve: {
alias: {
'@': path.resolve(__dirname, 'src/'),
utils: path.resolve(__dirname, 'src/utils/'),
mock: path.resolve(__dirname, 'src/mock/')
},
extensions: ['.ts', '.js']
},
devtool: 'source-map',
devServer: {
contentBase: './dist'
},
plugins: [
new CleanWebpackPlugin(),
new ESlintPlugin({
files: ['src/**/*.ts', 'src/**/*.js']
})
],
output: {
filename: '[name].js',
path: path.resolve(__dirname, 'dist')
}
}