This repository has been archived by the owner on Jul 10, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebpack.dev.js
95 lines (88 loc) · 2.44 KB
/
webpack.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
const fs = require("fs")
const path = require("path")
const webpack = require("webpack")
const merge = require("webpack-merge")
const BundleAnalyzerPlugin = require("webpack-bundle-analyzer").BundleAnalyzerPlugin
const CopyWebpackPlugin = require("copy-webpack-plugin")
const HtmlWebpackPlugin = require("html-webpack-plugin")
const common = require("./webpack.common")
const mode = "development"
const devServerHost = "localhost"
const devServerPort = 3000
const devServerUrl = `http://${devServerHost}:${devServerPort}/`
const templateContent = () => {
const html = fs.readFileSync(path.resolve(process.cwd(), common.htmlTemplatePath)).toString()
const bodyClosingStart = html.indexOf("</body>")
return `
${html.substring(0, bodyClosingStart)}
<script
type="text/javascript"
src="${devServerUrl}${common.dllConfig.vendorBundleFilename}">
</script>
<script
type="text/javascript"
src="${devServerUrl}${common.rendererConfig.output.filename}">
</script>
${html.substring(bodyClosingStart)}
`
}
const mainConfig = merge(common.mainConfig, {
mode: mode,
node: {
__dirname: false,
__filename: false
},
plugins: [
new webpack.DefinePlugin({
"process.env": {
NODE_ENV: JSON.stringify("dev")
}
}),
new HtmlWebpackPlugin({
templateContent: templateContent(),
inject: false
})
]
})
const rendererConfig = merge(common.rendererConfig, {
mode: mode,
entry: [
"babel-polyfill",
`webpack-dev-server/client?${devServerUrl}`,
"webpack/hot/only-dev-server",
common.rendererEntry
],
output: {
publicPath: common.devServerUrl
},
plugins: [
new CopyWebpackPlugin([
{
from: path.join(
__dirname,
common.dllConfig.dllRelativePath,
common.dllConfig.vendorBundleFilename
)
}
]),
new webpack.HotModuleReplacementPlugin(),
new webpack.NamedModulesPlugin(),
new webpack.DllReferencePlugin({
context: __dirname,
manifest: require(path.join(
__dirname,
common.dllConfig.dllRelativePath,
common.dllConfig.vendorManifestFilename
))
})
//new BundleAnalyzerPlugin()
],
devServer: {
host: devServerHost,
port: devServerPort,
contentBase: path.join(__dirname, "out"),
hot: true
}
})
const isDevServer = process.argv.find(v => v.includes("webpack-dev-server"))
module.exports = isDevServer ? rendererConfig : mainConfig