@lilaquadrat/design-core 0.2.1 → 0.2.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/README.md
CHANGED
|
@@ -54,6 +54,11 @@ optimizeDeps: { exclude: ['@lilaquadrat/studio', '@lilaquadrat/design-core'] }
|
|
|
54
54
|
|
|
55
55
|
`createViteConfig` already sets that.
|
|
56
56
|
|
|
57
|
+
The exception is the tooling Node loads itself at config time (`tooling/vite`):
|
|
58
|
+
Node refuses to strip types for files under `node_modules`, so a published copy
|
|
59
|
+
would never load as `.ts`. Those entries ship as plain `.js` with a `.d.ts`
|
|
60
|
+
beside them for the types.
|
|
61
|
+
|
|
57
62
|
## Using it in a design
|
|
58
63
|
|
|
59
64
|
### vite
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lilaquadrat/design-core",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "framework layer shared by every lilaquadrat STUDIO design: app bootstrap, router, stores, plugins and build tooling",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"./views/*": "./src/views/*",
|
|
48
48
|
"./partials/*": "./src/components/partials/*",
|
|
49
49
|
"./html/*": "./html/*",
|
|
50
|
-
"./vite": "./tooling/vite.
|
|
50
|
+
"./vite": "./tooling/vite.js",
|
|
51
51
|
"./eslint": "./tooling/eslint.config.js",
|
|
52
52
|
"./stylelint": "./tooling/stylelint.config.mjs",
|
|
53
53
|
"./cypress": "./tooling/cypress/config.ts",
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import type { Plugin, UserConfig } from 'vite';
|
|
2
|
-
|
|
3
1
|
const OUTPUT_DIR = 'dist/preview';
|
|
4
2
|
const PREVIEW_ASSET_DIR = 'previewAssets';
|
|
5
3
|
|
|
6
|
-
function escapeRegExp (input
|
|
4
|
+
function escapeRegExp (input) {
|
|
7
5
|
|
|
8
6
|
return input.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
9
7
|
|
|
@@ -16,13 +14,13 @@ function escapeRegExp (input: string) {
|
|
|
16
14
|
* while transforming - so even though rolldown tree shakes preview.view.vue out
|
|
17
15
|
* of the app bundle, the images survive as orphans nobody references.
|
|
18
16
|
*/
|
|
19
|
-
export function dropPreviewAssets ()
|
|
17
|
+
export function dropPreviewAssets () {
|
|
20
18
|
|
|
21
19
|
return {
|
|
22
20
|
name : 'drop-preview-assets',
|
|
23
21
|
enforce: 'post',
|
|
24
22
|
apply : 'build',
|
|
25
|
-
generateBundle (_options, bundle
|
|
23
|
+
generateBundle (_options, bundle) {
|
|
26
24
|
|
|
27
25
|
Object.keys(bundle).forEach((fileName) => {
|
|
28
26
|
|
|
@@ -30,7 +28,7 @@ export function dropPreviewAssets (): Plugin {
|
|
|
30
28
|
|
|
31
29
|
if(single.type !== 'asset') return;
|
|
32
30
|
|
|
33
|
-
const origins
|
|
31
|
+
const origins = [single.originalFileName, ...single.originalFileNames ?? []].filter(Boolean);
|
|
34
32
|
|
|
35
33
|
if(origins.some((origin) => origin.includes(PREVIEW_ASSET_DIR))) delete bundle[fileName];
|
|
36
34
|
|
|
@@ -47,7 +45,7 @@ export function dropPreviewAssets (): Plugin {
|
|
|
47
45
|
* everything here exists because the output is opened straight from disk, where
|
|
48
46
|
* each file is its own opaque origin.
|
|
49
47
|
*/
|
|
50
|
-
export function previewBuildOptions (base
|
|
48
|
+
export function previewBuildOptions (base) {
|
|
51
49
|
|
|
52
50
|
return {
|
|
53
51
|
...base,
|
|
@@ -75,13 +73,13 @@ export function previewBuildOptions (base: UserConfig['build']): UserConfig['bui
|
|
|
75
73
|
* folds the script and the stylesheet into index.html, so the preview is a self
|
|
76
74
|
* contained file that opens over file:// with no server.
|
|
77
75
|
*/
|
|
78
|
-
export default function previewBundle ()
|
|
76
|
+
export default function previewBundle () {
|
|
79
77
|
|
|
80
78
|
return {
|
|
81
79
|
name : 'preview-bundle',
|
|
82
80
|
enforce: 'post',
|
|
83
81
|
apply : 'build',
|
|
84
|
-
generateBundle (_options, bundle
|
|
82
|
+
generateBundle (_options, bundle) {
|
|
85
83
|
|
|
86
84
|
const html = bundle['index.html'];
|
|
87
85
|
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { Plugin, UserConfig, UserConfigFnObject } from 'vite';
|
|
2
|
+
|
|
3
|
+
export type Target = 'local' | 'next' | 'live';
|
|
4
|
+
|
|
5
|
+
export interface ViteFactoryOptions {
|
|
6
|
+
/**
|
|
7
|
+
* the project config keyed by target, as exported from its own config.ts.
|
|
8
|
+
* it is only serialised into __FRONTEND_CONFIG__, so its shape is the
|
|
9
|
+
* project's business
|
|
10
|
+
*/
|
|
11
|
+
config: Record<Target, unknown>
|
|
12
|
+
/**
|
|
13
|
+
* absolute path to the project root (the folder holding index.html)
|
|
14
|
+
*/
|
|
15
|
+
root: string
|
|
16
|
+
/**
|
|
17
|
+
* project relative path to the less folder holding variables, mixins and
|
|
18
|
+
* fonts - these are the design and never ship with the package
|
|
19
|
+
*/
|
|
20
|
+
lessDir?: string
|
|
21
|
+
/**
|
|
22
|
+
* project relative entry for the ssr build
|
|
23
|
+
*/
|
|
24
|
+
ssrEntry?: string
|
|
25
|
+
/**
|
|
26
|
+
* project relative entry for the ssr preflight fixtures (mode ssr-test).
|
|
27
|
+
* it exports the design's viewData and module registries so the test suite
|
|
28
|
+
* can read them without a bundler of its own
|
|
29
|
+
*/
|
|
30
|
+
ssrFixturesEntry?: string
|
|
31
|
+
/**
|
|
32
|
+
* additional defines merged over the framework ones
|
|
33
|
+
*/
|
|
34
|
+
define?: Record<string, string>
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function createViteConfig (options: ViteFactoryOptions): UserConfigFnObject;
|
|
38
|
+
export default createViteConfig;
|
|
39
|
+
|
|
40
|
+
export function previewBundle (): Plugin;
|
|
41
|
+
export function dropPreviewAssets (): Plugin;
|
|
42
|
+
export function previewBuildOptions (base: UserConfig['build']): UserConfig['build'];
|
|
@@ -2,48 +2,14 @@ import { fileURLToPath, URL } from 'node:url';
|
|
|
2
2
|
import { existsSync } from 'node:fs';
|
|
3
3
|
import { resolve } from 'node:path';
|
|
4
4
|
|
|
5
|
-
import { defineConfig
|
|
5
|
+
import { defineConfig } from 'vite';
|
|
6
6
|
import vue from '@vitejs/plugin-vue';
|
|
7
7
|
|
|
8
8
|
import { visualizer } from 'rollup-plugin-visualizer';
|
|
9
9
|
|
|
10
|
-
import previewBundle, { dropPreviewAssets, previewBuildOptions } from './preview.plugin.
|
|
10
|
+
import previewBundle, { dropPreviewAssets, previewBuildOptions } from './preview.plugin.js';
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
export interface ViteFactoryOptions {
|
|
15
|
-
/**
|
|
16
|
-
* the project config keyed by target, as exported from its own config.ts.
|
|
17
|
-
* it is only serialised into __FRONTEND_CONFIG__, so its shape is the
|
|
18
|
-
* project's business
|
|
19
|
-
*/
|
|
20
|
-
config: Record<Target, unknown>
|
|
21
|
-
/**
|
|
22
|
-
* absolute path to the project root (the folder holding index.html)
|
|
23
|
-
*/
|
|
24
|
-
root: string
|
|
25
|
-
/**
|
|
26
|
-
* project relative path to the less folder holding variables, mixins and
|
|
27
|
-
* fonts - these are the design and never ship with the package
|
|
28
|
-
*/
|
|
29
|
-
lessDir?: string
|
|
30
|
-
/**
|
|
31
|
-
* project relative entry for the ssr build
|
|
32
|
-
*/
|
|
33
|
-
ssrEntry?: string
|
|
34
|
-
/**
|
|
35
|
-
* project relative entry for the ssr preflight fixtures (mode ssr-test).
|
|
36
|
-
* it exports the design's viewData and module registries so the test suite
|
|
37
|
-
* can read them without a bundler of its own
|
|
38
|
-
*/
|
|
39
|
-
ssrFixturesEntry?: string
|
|
40
|
-
/**
|
|
41
|
-
* additional defines merged over the framework ones
|
|
42
|
-
*/
|
|
43
|
-
define?: Record<string, string>
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
function resolveTarget (mode: string): Target {
|
|
12
|
+
function resolveTarget (mode) {
|
|
47
13
|
|
|
48
14
|
if(mode === 'production') return 'live';
|
|
49
15
|
if(mode === 'next') return 'next';
|
|
@@ -57,7 +23,7 @@ function resolveTarget (mode: string): Target {
|
|
|
57
23
|
* override either by keeping a file of the same name in its root, otherwise the
|
|
58
24
|
* package template is used.
|
|
59
25
|
*/
|
|
60
|
-
function resolveTemplate (root
|
|
26
|
+
function resolveTemplate (root, name) {
|
|
61
27
|
|
|
62
28
|
const projectTemplate = resolve(root, name);
|
|
63
29
|
|
|
@@ -67,7 +33,7 @@ function resolveTemplate (root: string, name: string) {
|
|
|
67
33
|
|
|
68
34
|
}
|
|
69
35
|
|
|
70
|
-
export function createViteConfig (options
|
|
36
|
+
export function createViteConfig (options) {
|
|
71
37
|
|
|
72
38
|
/**
|
|
73
39
|
* absolute on purpose: the globalVars below are prepended to every less file,
|
|
@@ -78,7 +44,7 @@ export function createViteConfig (options: ViteFactoryOptions) {
|
|
|
78
44
|
const ssrEntry = options.ssrEntry ?? '/src/server-entry.ts';
|
|
79
45
|
const ssrFixturesEntry = options.ssrFixturesEntry ?? '/src/ssr-test.fixtures.ts';
|
|
80
46
|
|
|
81
|
-
return defineConfig((settings)
|
|
47
|
+
return defineConfig((settings) => {
|
|
82
48
|
|
|
83
49
|
const target = resolveTarget(settings.mode);
|
|
84
50
|
const isProduction = target === 'live';
|
|
@@ -99,7 +65,7 @@ export function createViteConfig (options: ViteFactoryOptions) {
|
|
|
99
65
|
*/
|
|
100
66
|
const isOptimized = isProduction || isPreview;
|
|
101
67
|
const config = options.config[target];
|
|
102
|
-
const viteConfig
|
|
68
|
+
const viteConfig = {
|
|
103
69
|
plugins: [
|
|
104
70
|
vue(),
|
|
105
71
|
visualizer(),
|
|
@@ -137,7 +103,7 @@ export function createViteConfig (options: ViteFactoryOptions) {
|
|
|
137
103
|
{ name: 'vendor', test: /[\\/]node_modules[\\/]/ },
|
|
138
104
|
],
|
|
139
105
|
},
|
|
140
|
-
assetFileNames: (assetInfo
|
|
106
|
+
assetFileNames: (assetInfo) => {
|
|
141
107
|
if (assetInfo.name?.endsWith('woff') || assetInfo.name?.endsWith('png')) {
|
|
142
108
|
return '[name][extname]';
|
|
143
109
|
}
|