This repository has been archived by the owner on Feb 19, 2022. It is now read-only.
/
webpack.config.js
86 lines (79 loc) · 2.26 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
"use strict";
/**
* Webpack configuration
*/
var path = require("path");
var StatsWriterPlugin = require("webpack-stats-plugin").StatsWriterPlugin;
var DiskPlugin = require("../lib/index");
module.exports = {
cache: true,
context: __dirname,
entry: "./main.js",
output: {
path: path.join(__dirname, "build"),
publicPath: "/assets/",
filename: "deadbeef012345678901.main.js" // Simulate a hash for determinacy.
},
plugins: [
// Outputs `stats.json`
new StatsWriterPlugin(),
// Various disk plugin scenarios...
// Noops.
new DiskPlugin(),
new DiskPlugin({}),
new DiskPlugin({
output: { path: "build-0" }
}),
// Basic scenarios.
new DiskPlugin({ // build-1/
output: { path: "build-1" },
files: [
{ asset: "stats.json" }
]
}),
new DiskPlugin({ // build-2/
output: { path: "build-2" },
files: [
{ asset: "stats.json", output: { filename: path.join(__dirname, "build-2/stats.json") } },
{ asset: /[a-f0-9]{20}\.main\.js/, output: { path: "build-2" } },
{ asset: /[a-f0-9]{20}\.main\.js/, output: { filename: "copy.js" } }
]
}),
new DiskPlugin({ // build-3/
files: [
{ asset: "stats.json", output: { path: "build-3" } },
{ asset: /[a-f0-9]{20}\.main\.js/, output: { path: "build-3", filename: "yo.js" } }
]
}),
// Advanced
new DiskPlugin({ // build-4/
output: { path: "build-4" },
files: [
{ asset: "stats.json", output: { filename: "nested/stats.json" } },
{
asset: /[a-f0-9]{20}\.main\.js/,
output: {
// Custom namer: invert the hash.
filename: function (name) {
return "main." + name.match(/[a-f0-9]{20}/)[0] + ".js";
}
}
}
]
}),
// // EXPECTED FAILURE
// new DiskPlugin({
// files: [
// { asset: "stats.json" },
// { asset: "stats.json", output: { filename: "stats.json" } }
// ]
// }),
// HACK: Terminate the entire process so that we can use `webpack-dev-server`
// in a one-shot manner to check real FS output.
{
apply: function (compiler) {
compiler.plugin("after-emit", process.exit.bind(null, 0));
}
}
]
};