@ditojs/build 3.2.6 → 3.3.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ditojs/build",
3
- "version": "3.2.6",
3
+ "version": "3.3.0",
4
4
  "type": "module",
5
5
  "repository": "https://github.com/ditojs/dito/tree/main/packages/build",
6
6
  "author": "Jürg Lehni <juerg@scratchdisk.com> (http://scratchdisk.com)",
@@ -24,19 +24,19 @@
24
24
  "node >= 18"
25
25
  ],
26
26
  "dependencies": {
27
- "@ditojs/utils": "^3.2.6",
27
+ "@ditojs/utils": "^3.3.0",
28
28
  "@vitejs/plugin-vue": "^6.0.9",
29
29
  "autoprefixer": "^10.6.1",
30
30
  "mime": "^4.1.0",
31
31
  "mini-svg-data-uri": "^1.4.4",
32
32
  "minimist": "^1.2.8",
33
- "postcss": "^8.5.28",
33
+ "postcss": "^8.5.29",
34
34
  "postcss-html": "^2.0.0",
35
35
  "postcss-scss": "^4.0.9",
36
36
  "pug": "^3.0.4",
37
37
  "sass": "^1.105.1",
38
- "vite": "^8.3.2",
38
+ "vite": "^8.3.4",
39
39
  "vue": "^3.5.43"
40
40
  },
41
- "gitHead": "d9868ae96d60a70b5e7ba89a5fc91e07b267a0d5"
41
+ "gitHead": "1ba6ba0a6642294959966a3488b0944c7c321b39"
42
42
  }
package/src/css.js CHANGED
@@ -3,7 +3,7 @@ import mime from 'mime'
3
3
  import svgToDataUri from 'mini-svg-data-uri'
4
4
 
5
5
  export function getDataUri(filePath) {
6
- const content = fs.readFileSync(filePath, 'utf8')
6
+ const content = fs.readFileSync(filePath)
7
7
  const type = mime.getType(filePath)
8
8
  return type === 'image/svg+xml'
9
9
  ? svgToDataUri(content.toString('utf8'))
package/src/rollup.js CHANGED
@@ -37,6 +37,31 @@ export function getRollupExternalsFromDependencies({
37
37
  return externals
38
38
  }
39
39
 
40
+ // Dito.js packages expose their sources through a `/src` export, so that other
41
+ // Dito.js packages can bundle them, e.g. `@ditojs/ui/src` in `@ditojs/admin`:
42
+ const bundledSourcesRegexp = /^@ditojs\/[^/]+\/src(\/|$)/
43
+
44
+ export function getPackageName(id) {
45
+ // Relative and absolute paths and virtual modules aren't packages:
46
+ if (/^[./\0]/.test(id) || /^[a-z]+:/i.test(id)) return null
47
+ const parts = id.split('/')
48
+ return id.startsWith('@') ? parts.slice(0, 2).join('/') : parts[0]
49
+ }
50
+
51
+ // Style sheets, optionally followed by a query, e.g. `tippy.js/dist/tippy.css`
52
+ // or `vue-color/style.css?inline`:
53
+ const styleSheetRegexp = /\.(css|scss|sass|less|styl|stylus|pcss|postcss)(\?|$)/
54
+
55
+ export function isRollupExternal(id, externals) {
56
+ if (externals[id]) return true
57
+ if (bundledSourcesRegexp.test(id)) return false
58
+ // Style sheets of external packages are bundled into the CSS output:
59
+ if (styleSheetRegexp.test(id)) return false
60
+ // Subpaths of external packages are external too, e.g. `@tiptap/pm/model`:
61
+ const packageName = getPackageName(id)
62
+ return !!packageName && packageName !== id && !!externals[packageName]
63
+ }
64
+
40
65
  export function matchModuleIdentifier(id, pattern) {
41
66
  const regexp = new RegExp(`^${escapeRegexp(pattern).replace('\\*', '(.*)')}$`)
42
67
  const match = id.match(regexp)
package/src/vite.js CHANGED
@@ -1,7 +1,10 @@
1
1
  import { defineConfig as viteDefineConfig } from 'vite'
2
2
  import createVuePlugin from '@vitejs/plugin-vue'
3
3
  import { getPostCssConfig } from './postcss.js'
4
- import { getRollupExternalsFromDependencies } from './rollup.js'
4
+ import {
5
+ getRollupExternalsFromDependencies,
6
+ isRollupExternal
7
+ } from './rollup.js'
5
8
 
6
9
  export function defineViteConfig({
7
10
  defineConfig = viteDefineConfig,
@@ -17,6 +20,8 @@ export function defineViteConfig({
17
20
  include = [],
18
21
  exclude = []
19
22
  } = {},
23
+ // Options merged into `build.rollupOptions.output`, e.g. `exports`:
24
+ rollupOutput = {},
20
25
  ...rest
21
26
  } = {}) {
22
27
  const externals = (
@@ -46,10 +51,12 @@ export function defineViteConfig({
46
51
  cssFileName: name
47
52
  },
48
53
  rollupOptions: {
49
- external: id => !!externals[id],
54
+ external: id => isRollupExternal(id, externals),
50
55
  output: {
51
56
  manualChunks: undefined,
52
- globals: externals
57
+ // Use the module identifiers as UMD globals, including subpaths:
58
+ globals: id => id,
59
+ ...rollupOutput
53
60
  }
54
61
  }
55
62
  }