unplugin-version-injector 2.0.0-beta.1 → 2.0.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/rollup.d.mts +11 -0
- package/dist/rollup.d.ts +11 -0
- package/dist/webpack.js +17 -2
- package/dist/webpack.mjs +17 -2
- package/package.json +1 -1
@@ -0,0 +1,11 @@
|
|
1
|
+
import { Plugin } from 'rollup';
|
2
|
+
|
3
|
+
interface VersionInjectorOptions {
|
4
|
+
version?: string;
|
5
|
+
log?: boolean;
|
6
|
+
formatDate?: (date: Date) => string;
|
7
|
+
}
|
8
|
+
|
9
|
+
declare function versionInjector(options?: VersionInjectorOptions): Plugin;
|
10
|
+
|
11
|
+
export { versionInjector as default };
|
package/dist/rollup.d.ts
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
import { Plugin } from 'rollup';
|
2
|
+
|
3
|
+
interface VersionInjectorOptions {
|
4
|
+
version?: string;
|
5
|
+
log?: boolean;
|
6
|
+
formatDate?: (date: Date) => string;
|
7
|
+
}
|
8
|
+
|
9
|
+
declare function versionInjector(options?: VersionInjectorOptions): Plugin;
|
10
|
+
|
11
|
+
export { versionInjector as default };
|
package/dist/webpack.js
CHANGED
@@ -58,12 +58,15 @@ function versionInjectorPlugin(options = {}) {
|
|
58
58
|
return {
|
59
59
|
apply(compiler) {
|
60
60
|
var _a, _b;
|
61
|
-
const isWebpack5 = (_b = (_a = compiler.webpack) == null ? void 0 : _a.version) == null ? void 0 : _b.startsWith("5");
|
61
|
+
const isWebpack5 = Boolean((_b = (_a = compiler.webpack) == null ? void 0 : _a.version) == null ? void 0 : _b.startsWith("5"));
|
62
62
|
compiler.hooks.compilation.tap("webpack-version-injector", (compilation) => {
|
63
63
|
if (isWebpack5) {
|
64
64
|
const { Compilation, sources } = compiler.webpack;
|
65
65
|
compilation.hooks.processAssets.tap(
|
66
|
-
{
|
66
|
+
{
|
67
|
+
name: "webpack-version-injector",
|
68
|
+
stage: Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_INLINE
|
69
|
+
},
|
67
70
|
(assets) => {
|
68
71
|
for (const name in assets) {
|
69
72
|
if (name.endsWith(".html")) {
|
@@ -74,6 +77,18 @@ function versionInjectorPlugin(options = {}) {
|
|
74
77
|
}
|
75
78
|
}
|
76
79
|
);
|
80
|
+
} else {
|
81
|
+
compiler.hooks.emit.tapAsync("webpack-version-injector", (compilation2, callback) => {
|
82
|
+
for (const name in compilation2.assets) {
|
83
|
+
if (name.endsWith(".html")) {
|
84
|
+
const html = compilation2.assets[name].source().toString();
|
85
|
+
const result = inject(html);
|
86
|
+
const { sources } = compiler.webpack;
|
87
|
+
compilation2.assets[name] = new sources.RawSource(result);
|
88
|
+
}
|
89
|
+
}
|
90
|
+
callback();
|
91
|
+
});
|
77
92
|
}
|
78
93
|
});
|
79
94
|
}
|
package/dist/webpack.mjs
CHANGED
@@ -51,12 +51,15 @@ function versionInjectorPlugin(options = {}) {
|
|
51
51
|
return {
|
52
52
|
apply(compiler) {
|
53
53
|
var _a, _b;
|
54
|
-
const isWebpack5 = (_b = (_a = compiler.webpack) == null ? void 0 : _a.version) == null ? void 0 : _b.startsWith("5");
|
54
|
+
const isWebpack5 = Boolean((_b = (_a = compiler.webpack) == null ? void 0 : _a.version) == null ? void 0 : _b.startsWith("5"));
|
55
55
|
compiler.hooks.compilation.tap("webpack-version-injector", (compilation) => {
|
56
56
|
if (isWebpack5) {
|
57
57
|
const { Compilation, sources } = compiler.webpack;
|
58
58
|
compilation.hooks.processAssets.tap(
|
59
|
-
{
|
59
|
+
{
|
60
|
+
name: "webpack-version-injector",
|
61
|
+
stage: Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_INLINE
|
62
|
+
},
|
60
63
|
(assets) => {
|
61
64
|
for (const name in assets) {
|
62
65
|
if (name.endsWith(".html")) {
|
@@ -67,6 +70,18 @@ function versionInjectorPlugin(options = {}) {
|
|
67
70
|
}
|
68
71
|
}
|
69
72
|
);
|
73
|
+
} else {
|
74
|
+
compiler.hooks.emit.tapAsync("webpack-version-injector", (compilation2, callback) => {
|
75
|
+
for (const name in compilation2.assets) {
|
76
|
+
if (name.endsWith(".html")) {
|
77
|
+
const html = compilation2.assets[name].source().toString();
|
78
|
+
const result = inject(html);
|
79
|
+
const { sources } = compiler.webpack;
|
80
|
+
compilation2.assets[name] = new sources.RawSource(result);
|
81
|
+
}
|
82
|
+
}
|
83
|
+
callback();
|
84
|
+
});
|
70
85
|
}
|
71
86
|
});
|
72
87
|
}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "unplugin-version-injector",
|
3
|
-
"version": "2.0.0-beta.
|
3
|
+
"version": "2.0.0-beta.2",
|
4
4
|
"author": "Nian Yi <nianyi778@gmail.com>",
|
5
5
|
"license": "MIT",
|
6
6
|
"description": "A universal plugin to inject version and build time into HTML (supports Webpack, Vite, Rollup)",
|