forked from seebox/BoxWebApp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.cp.dev.js
74 lines (67 loc) · 1.95 KB
/
webpack.cp.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
var path = require('path');
var fs = require('fs');
var webpack = require('webpack');
var app_config = require('./appconfig.js');
var devServer = app_config.getDevServer();
// console.log((devServer.gatewayHost?devServer.gatewayHost:devServer.ip));
var wp1 = 'webpack-dev-server/client?http://' + (devServer.gatewayHost?devServer.gatewayHost:devServer.ip) + ':' + devServer.port;
var wp2 = 'webpack/hot/only-dev-server';
var entries = {
// webdev:[
// wp1,wp2
// ]
};
var htmls = [];
(function getAllFiles(root) {
var files = fs.readdirSync(root);
files.forEach(function(file) {
var pathname = root + '/' + file,
stat = fs.lstatSync(pathname);
if (!stat.isDirectory()) {
if(file.endsWith('.jsx') && file !== 'Test.jsx'){
var entryName = file.substr(0,file.length-4);
entries[entryName] = [root + '/' + entryName, wp1, wp2];
}else if(!pathname.endsWith('devtests/index.html') && file.endsWith('.html')){
htmls.push(pathname);
}
} else {
getAllFiles(pathname);
}
});
})('./devtests');
var body='';
htmls.forEach((f)=>{
var fp = f.substr(11);
var tagA = `<p><a href="${fp}">${fp}</a></p>\n`;
body+=tagA;
console.log(tagA);
});
var htmlcontent = `<!DOCTYPE html>\n<html>\n<body>\n${body}</body>\n</html>\n`;
fs.writeFile('./devtests/index.html', htmlcontent);
module.exports = {
devtool: 'eval',
entry: entries,
output: {
path: path.join(__dirname, 'app/js'),
filename: '[name].js',
publicPath: '/debug/'
},
plugins: [
new webpack.HotModuleReplacementPlugin()
],
module: {
loaders: [{
test: /\.css$/,
loader: 'style!css'
}, {
test: /\.jsx$|\.js$/,
loaders: ['react-hot', 'babel'],
include: [path.join(__dirname, 'src'), path.join(__dirname, 'devtests')]
}]
},
resolve: {
root: [path.resolve(__dirname, 'src'), path.resolve(__dirname, 'devtests')],
extensions: ['', '.jsx', '.js', '.css'],
alias: app_config.alias
}
};