@imagexmedia/vite 0.0.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/LICENSE +21 -0
- package/README.md +1 -0
- package/configs/default.vite.config.js +3 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.js +77 -0
- package/dist/plugins/svg.d.ts +9 -0
- package/dist/plugins/svg.js +37 -0
- package/package.json +34 -0
- package/types/vite.d.ts +1 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) [year] [fullname]
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# SWAT Vite
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { UserConfig, UserConfigFnObject } from 'vite';
|
|
2
|
+
import type { ViteSvgOptions } from './plugins/svg.ts';
|
|
3
|
+
interface ViteOptions {
|
|
4
|
+
/**
|
|
5
|
+
* An object of resolvable aliases where the key is a name and the value is a directory.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* {
|
|
10
|
+
* aliases: {
|
|
11
|
+
* "@abstracts": path.resolve(process.cwd(), "src/abstracts"),
|
|
12
|
+
* }
|
|
13
|
+
* }
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* @see https://vite.dev/config/shared-options.html#resolve-alias
|
|
17
|
+
*/
|
|
18
|
+
aliases?: Record<string, string>;
|
|
19
|
+
plugins?: {
|
|
20
|
+
svg?: ViteSvgOptions;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Define Vite configuration.
|
|
25
|
+
*/
|
|
26
|
+
export declare function setConfig(options?: ViteOptions, config?: UserConfig | UserConfigFnObject): UserConfigFnObject;
|
|
27
|
+
export {};
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import process from 'node:process';
|
|
3
|
+
import merge from 'deepmerge';
|
|
4
|
+
import globby from 'globby';
|
|
5
|
+
import { defineConfig, mergeConfig } from 'vite';
|
|
6
|
+
import { registerSvgPlugins } from "./plugins/svg.js";
|
|
7
|
+
/**
|
|
8
|
+
* Define Vite configuration.
|
|
9
|
+
*/
|
|
10
|
+
export function setConfig(options = {}, config = {}) {
|
|
11
|
+
options = merge({
|
|
12
|
+
aliases: {},
|
|
13
|
+
plugins: {},
|
|
14
|
+
}, options);
|
|
15
|
+
const cwd = String(process.env.INIT_CWD);
|
|
16
|
+
const input = {};
|
|
17
|
+
const inputPatterns = [
|
|
18
|
+
// Look for inputs in the root source directory.
|
|
19
|
+
`${cwd}/src/*.{js,jsx,ts,tsx,css,scss}`,
|
|
20
|
+
// Look for inputs in the first-level subdirectories of the root source directory.
|
|
21
|
+
`${cwd}/src/*/*.{js,jsx,ts,tsx,css,scss}`,
|
|
22
|
+
];
|
|
23
|
+
inputPatterns.forEach((pattern) => {
|
|
24
|
+
if (Object.keys(input).length === 0) {
|
|
25
|
+
globby.sync(pattern).forEach((filepath) => {
|
|
26
|
+
const { name } = path.parse(filepath);
|
|
27
|
+
if (name.match(/^[^a-z0-9]/i))
|
|
28
|
+
return;
|
|
29
|
+
input[`${name}-${Object.keys(input).length}`] = filepath;
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
// Strip unique index from output filename.
|
|
34
|
+
const processFilename = (value) => {
|
|
35
|
+
return value.replace(/-\d+$/, '');
|
|
36
|
+
};
|
|
37
|
+
return defineConfig((env) => {
|
|
38
|
+
const baseConfig = {
|
|
39
|
+
plugins: [
|
|
40
|
+
...registerSvgPlugins(options.plugins?.svg),
|
|
41
|
+
],
|
|
42
|
+
publicDir: './static',
|
|
43
|
+
build: {
|
|
44
|
+
outDir: 'public',
|
|
45
|
+
sourcemap: env.mode !== 'production',
|
|
46
|
+
minify: env.mode === 'production',
|
|
47
|
+
rollupOptions: {
|
|
48
|
+
input,
|
|
49
|
+
output: {
|
|
50
|
+
entryFileNames: chunkInfo => `js/${processFilename(chunkInfo.name)}.js`,
|
|
51
|
+
assetFileNames: (assetInfo) => {
|
|
52
|
+
const { name, ext } = path.parse(assetInfo.names[0]);
|
|
53
|
+
return `${ext === '.css' ? 'css' : 'assets'}/${processFilename(name)}.[ext]`;
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
css: {
|
|
59
|
+
devSourcemap: env.mode !== 'production',
|
|
60
|
+
preprocessorOptions: {
|
|
61
|
+
scss: {
|
|
62
|
+
// Silence @import deprecation warning.
|
|
63
|
+
// @todo Remove silenced deprecation when Bootstrap 6 is released.
|
|
64
|
+
// https://github.com/twbs/bootstrap/pull/41512
|
|
65
|
+
silenceDeprecations: ['import'],
|
|
66
|
+
// Silence deprecation warnings in node modules.
|
|
67
|
+
quietDeps: true,
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
resolve: {
|
|
72
|
+
alias: options.aliases,
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
return mergeConfig(baseConfig, typeof config === 'function' ? config(env) : config);
|
|
76
|
+
});
|
|
77
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Config } from 'svgo';
|
|
2
|
+
import type { PluginOption } from 'vite';
|
|
3
|
+
export interface ViteSvgOptions {
|
|
4
|
+
/**
|
|
5
|
+
* Optional SVGO configuration overrides.
|
|
6
|
+
*/
|
|
7
|
+
svgo?: Config;
|
|
8
|
+
}
|
|
9
|
+
export declare function registerSvgPlugins(options?: ViteSvgOptions): PluginOption[];
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import VitePluginSvgSpritemap from '@spiriit/vite-plugin-svg-spritemap';
|
|
2
|
+
import merge from 'deepmerge';
|
|
3
|
+
import { ViteImageOptimizer } from 'vite-plugin-image-optimizer';
|
|
4
|
+
const baseConfig = {
|
|
5
|
+
multipass: true,
|
|
6
|
+
plugins: [
|
|
7
|
+
{
|
|
8
|
+
name: 'preset-default',
|
|
9
|
+
params: {
|
|
10
|
+
overrides: {
|
|
11
|
+
cleanupIds: false,
|
|
12
|
+
},
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
name: 'removeAttrs',
|
|
17
|
+
params: {
|
|
18
|
+
attrs: '*:(stroke|fill):((?!^var|url).)*',
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
'removeDimensions',
|
|
22
|
+
],
|
|
23
|
+
};
|
|
24
|
+
export function registerSvgPlugins(options) {
|
|
25
|
+
return [
|
|
26
|
+
ViteImageOptimizer({
|
|
27
|
+
test: /\.(svg)$/i,
|
|
28
|
+
includePublic: true,
|
|
29
|
+
svg: merge(baseConfig, options?.svgo || {}),
|
|
30
|
+
}),
|
|
31
|
+
VitePluginSvgSpritemap('src/icons/*.svg', {
|
|
32
|
+
output: 'icons-sprite.svg',
|
|
33
|
+
// SVG assets in the public directory are optimized after the build.
|
|
34
|
+
svgo: false,
|
|
35
|
+
}),
|
|
36
|
+
];
|
|
37
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@imagexmedia/vite",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "0.0.1",
|
|
5
|
+
"description": "The ImageX SWAT Vite package.",
|
|
6
|
+
"author": "ImageX Media",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": "./dist/index.js",
|
|
10
|
+
"./plugins/svg": {
|
|
11
|
+
"types": "./dist/plugins/svg.d.ts",
|
|
12
|
+
"default": "./dist/plugins/svg.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"main": "dist/index.js",
|
|
16
|
+
"types": "dist/index.d.ts",
|
|
17
|
+
"files": [
|
|
18
|
+
"LICENSE",
|
|
19
|
+
"README.md",
|
|
20
|
+
"configs",
|
|
21
|
+
"dist",
|
|
22
|
+
"types"
|
|
23
|
+
],
|
|
24
|
+
"scripts": {
|
|
25
|
+
"build": "rm -rf dist && tsc -b && mkdir -p packs && npm pack --pack-destination packs"
|
|
26
|
+
},
|
|
27
|
+
"peerDependencies": {
|
|
28
|
+
"@spiriit/vite-plugin-svg-spritemap": "^5.0.0",
|
|
29
|
+
"sass-embedded": "^1.95.1",
|
|
30
|
+
"svgo": "^4.0.0",
|
|
31
|
+
"vite": "^7.2.7",
|
|
32
|
+
"vite-plugin-image-optimizer": "^2.0.3"
|
|
33
|
+
}
|
|
34
|
+
}
|
package/types/vite.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import type {} from 'vite/client'
|