-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathwebpack.config.js
More file actions
83 lines (73 loc) · 1.75 KB
/
webpack.config.js
File metadata and controls
83 lines (73 loc) · 1.75 KB
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
/* eslint-disable @typescript-eslint/no-var-requires */
var webpack = require('webpack')
var path = require('path')
var fs = require('fs')
process.noDeprecation = true
// 遍历demo下面所有目录层级,使用所有js作为entry
function getDemoEntry(dirPath, entries) {
var reg = /.ts$/
var pageDir = fs.readdirSync(dirPath) || []
for (var j = 0; j < pageDir.length; j++) {
var filePath = path.resolve(dirPath, pageDir[j])
var fileStat = fs.statSync(filePath)
if (fileStat.isFile()) {
if (reg.test(pageDir[j])) {
var name = pageDir[j].replace('.js', '')
if (entries[name]) {
console.log('\x1b[31m')
console.log('entry name 冲突: ' + name)
console.log('\t', entries[name][0])
console.log('\t', filePath)
console.log('\x1b[0m')
}
entries[name] = [filePath]
}
} else if (fileStat.isDirectory()) {
getDemoEntry(filePath, entries)
}
}
return entries
}
var ENTRY = process.env.ENTRY
var entry = {}
if (ENTRY) {
// 手动指定一个特定entry
entry[ENTRY] = ['./demo/' + ENTRY + '.js']
} else {
// 查找demo目录下所有的js文件作为entry
getDemoEntry(path.resolve(__dirname, 'demo/'), entry)
}
var config = {
entry: entry,
output: {
path: path.resolve(__dirname, 'build'),
filename: '[name].demo.js',
publicPath: '/static/',
// globalObject: "this",
},
mode: 'development',
plugins: [
new webpack.NoEmitOnErrorsPlugin(), // 出错时不发布
],
resolve: {
alias: { src: path.join(__dirname, 'src') },
extensions: ['.js', '.css', '.ts'],
},
module: {
rules: [
{
test: /\.ts$/,
include: /src|demo/,
use: {
loader: 'ts-loader',
options: {
compilerOptions: {
rootDir: './',
},
},
},
},
],
},
}
module.exports = config