@imagexmedia/vite 0.0.3 → 0.0.4-beta.1

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/index.js CHANGED
@@ -3,6 +3,7 @@ import process from 'node:process';
3
3
  import merge from 'deepmerge';
4
4
  import globby from 'globby';
5
5
  import { defineConfig, mergeConfig } from 'vite';
6
+ import { registerCssPlugins } from "./plugins/css.js";
6
7
  import { registerSvgPlugins } from "./plugins/svg.js";
7
8
  /**
8
9
  * Define Vite configuration.
@@ -37,6 +38,7 @@ export function setConfig(options = {}, config = {}) {
37
38
  return defineConfig((env) => {
38
39
  const baseConfig = {
39
40
  plugins: [
41
+ ...registerCssPlugins(),
40
42
  ...registerSvgPlugins(options.plugins?.svg),
41
43
  ],
42
44
  publicDir: './static',
@@ -0,0 +1,5 @@
1
+ import type { ResolvedConfig } from 'vite';
2
+ export declare function registerCssPlugins(): {
3
+ name: string;
4
+ configResolved(config: ResolvedConfig): void;
5
+ }[];
@@ -0,0 +1,40 @@
1
+ import { Buffer } from 'node:buffer';
2
+ import fs from 'node:fs';
3
+ import path from 'node:path';
4
+ function cssSourcemap() {
5
+ return {
6
+ name: 'css-sourcemap',
7
+ configResolved(config) {
8
+ if (config.command !== 'build' || !config.css.devSourcemap)
9
+ return;
10
+ const plugin = config.plugins.find((v) => v.name === 'vite:css');
11
+ const transformHandler = plugin?.transform.handler;
12
+ if (!plugin || !transformHandler)
13
+ return;
14
+ plugin.transform.handler = async function (raw, id) {
15
+ const result = await transformHandler.call(this, raw, id);
16
+ if (result.map?.mappings) {
17
+ result.map.sourcesContent = [];
18
+ const outDir = path.join(config.root, config.build.outDir, config.build.assetsDir);
19
+ result.map.sources = result.map.sources.map((source, index) => {
20
+ try {
21
+ result.map.sourcesContent[index] = fs.readFileSync(source, 'utf-8');
22
+ }
23
+ catch {
24
+ result.map.sourcesContent[index] = null;
25
+ }
26
+ return path.relative(outDir, source);
27
+ });
28
+ const mapEncoded = Buffer.from(JSON.stringify(result.map)).toString('base64');
29
+ result.code += `\n/*# sourceMappingURL=data:application/json;base64,${mapEncoded} */`;
30
+ }
31
+ return result;
32
+ };
33
+ },
34
+ };
35
+ }
36
+ export function registerCssPlugins() {
37
+ // @todo Review and possibly remove when Vite stabilizes the devSourcemap option.
38
+ // https://github.com/vitejs/vite/discussions/13845
39
+ return [cssSourcemap()];
40
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@imagexmedia/vite",
3
3
  "type": "module",
4
- "version": "0.0.3",
4
+ "version": "0.0.4-beta.1",
5
5
  "description": "The ImageX SWAT Vite package.",
6
6
  "author": "ImageX Media",
7
7
  "license": "MIT",