@homebound/truss 2.8.2 → 2.8.4
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/build/index.js +8 -1
- package/build/index.js.map +1 -1
- package/build/plugin/index.d.ts +0 -1
- package/build/plugin/index.js +8 -27
- package/build/plugin/index.js.map +1 -1
- package/package.json +1 -1
package/build/plugin/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// src/plugin/index.ts
|
|
2
|
-
import { readFileSync as readFileSync3,
|
|
3
|
-
import { resolve as resolve2, dirname, isAbsolute
|
|
2
|
+
import { readFileSync as readFileSync3, existsSync } from "fs";
|
|
3
|
+
import { resolve as resolve2, dirname, isAbsolute } from "path";
|
|
4
4
|
|
|
5
5
|
// src/plugin/emit-truss.ts
|
|
6
6
|
import * as t from "@babel/types";
|
|
@@ -3008,7 +3008,11 @@ function trussPlugin(opts) {
|
|
|
3008
3008
|
});
|
|
3009
3009
|
},
|
|
3010
3010
|
transformIndexHtml(html) {
|
|
3011
|
-
if (isBuild)
|
|
3011
|
+
if (isBuild) {
|
|
3012
|
+
const link = `<link rel="stylesheet" href="./truss.css">`;
|
|
3013
|
+
return html.replace("</head>", ` ${link}
|
|
3014
|
+
</head>`);
|
|
3015
|
+
}
|
|
3012
3016
|
const tag = `<script type="module" src="/${VIRTUAL_RUNTIME_ID}"></script>`;
|
|
3013
3017
|
return html.replace("</head>", ` ${tag}
|
|
3014
3018
|
</head>`);
|
|
@@ -3119,38 +3123,15 @@ __injectTrussCSS(${JSON.stringify(css)});
|
|
|
3119
3123
|
return { code: result.code, map: result.map };
|
|
3120
3124
|
},
|
|
3121
3125
|
// -- Production CSS emission --
|
|
3122
|
-
generateBundle(_options,
|
|
3126
|
+
generateBundle(_options, _bundle) {
|
|
3123
3127
|
if (!isBuild) return;
|
|
3124
3128
|
const css = collectCss();
|
|
3125
3129
|
if (!css) return;
|
|
3126
|
-
for (const key of Object.keys(bundle)) {
|
|
3127
|
-
const asset = bundle[key];
|
|
3128
|
-
if (asset.type === "asset" && key.endsWith(".css")) {
|
|
3129
|
-
asset.source = asset.source + "\n" + css;
|
|
3130
|
-
return;
|
|
3131
|
-
}
|
|
3132
|
-
}
|
|
3133
3130
|
this.emitFile({
|
|
3134
3131
|
type: "asset",
|
|
3135
3132
|
fileName: "truss.css",
|
|
3136
3133
|
source: css
|
|
3137
3134
|
});
|
|
3138
|
-
},
|
|
3139
|
-
writeBundle(options, bundle) {
|
|
3140
|
-
if (!isBuild) return;
|
|
3141
|
-
const css = collectCss();
|
|
3142
|
-
if (!css) return;
|
|
3143
|
-
const outDir = options.dir || join2(projectRoot, "dist");
|
|
3144
|
-
const trussPath = join2(outDir, "truss.css");
|
|
3145
|
-
if (!existsSync(trussPath)) {
|
|
3146
|
-
const alreadyEmitted = Object.keys(bundle).some((key) => {
|
|
3147
|
-
const asset = bundle[key];
|
|
3148
|
-
return asset.type === "asset" && key.endsWith(".css") && typeof asset.source === "string" && asset.source.includes(css);
|
|
3149
|
-
});
|
|
3150
|
-
if (!alreadyEmitted) {
|
|
3151
|
-
writeFileSync2(trussPath, css, "utf8");
|
|
3152
|
-
}
|
|
3153
|
-
}
|
|
3154
3135
|
}
|
|
3155
3136
|
};
|
|
3156
3137
|
}
|