@quilted/rollup 0.1.4 → 0.1.6

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.
Files changed (66) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/build/cjs/app.cjs +160 -142
  3. package/build/cjs/features/assets.cjs +130 -0
  4. package/build/cjs/features/css.cjs +71 -0
  5. package/build/cjs/{env.cjs → features/env.cjs} +4 -4
  6. package/build/cjs/{request-router.cjs → features/request-router.cjs} +3 -3
  7. package/build/cjs/{shared → features}/source-code.cjs +7 -2
  8. package/build/cjs/features/system-js.cjs +35 -0
  9. package/build/cjs/index.cjs +0 -7
  10. package/build/cjs/shared/rollup.cjs +0 -4
  11. package/build/esm/app.mjs +162 -144
  12. package/build/esm/features/assets.mjs +107 -0
  13. package/build/esm/features/css.mjs +69 -0
  14. package/build/esm/{env.mjs → features/env.mjs} +4 -4
  15. package/build/esm/{request-router.mjs → features/request-router.mjs} +3 -3
  16. package/build/esm/{shared → features}/source-code.mjs +6 -1
  17. package/build/esm/features/system-js.mjs +33 -0
  18. package/build/esm/index.mjs +1 -3
  19. package/build/esm/shared/rollup.mjs +1 -4
  20. package/build/esnext/app.esnext +162 -144
  21. package/build/esnext/features/assets.esnext +107 -0
  22. package/build/esnext/features/css.esnext +69 -0
  23. package/build/esnext/{env.esnext → features/env.esnext} +4 -4
  24. package/build/esnext/{request-router.esnext → features/request-router.esnext} +3 -3
  25. package/build/esnext/{shared → features}/source-code.esnext +6 -1
  26. package/build/esnext/features/system-js.esnext +33 -0
  27. package/build/esnext/index.esnext +1 -3
  28. package/build/esnext/shared/rollup.esnext +1 -4
  29. package/build/tsconfig.tsbuildinfo +1 -1
  30. package/build/typescript/app.d.ts +33 -144
  31. package/build/typescript/app.d.ts.map +1 -1
  32. package/build/typescript/features/assets.d.ts +13 -0
  33. package/build/typescript/features/assets.d.ts.map +1 -0
  34. package/build/typescript/features/css.d.ts +16 -0
  35. package/build/typescript/features/css.d.ts.map +1 -0
  36. package/build/typescript/features/env.d.ts +57 -0
  37. package/build/typescript/features/env.d.ts.map +1 -0
  38. package/build/typescript/features/graphql/transform.d.ts +17 -0
  39. package/build/typescript/features/graphql/transform.d.ts.map +1 -0
  40. package/build/typescript/features/graphql.d.ts +6 -0
  41. package/build/typescript/features/graphql.d.ts.map +1 -0
  42. package/build/typescript/features/request-router.d.ts +15 -0
  43. package/build/typescript/features/request-router.d.ts.map +1 -0
  44. package/build/typescript/features/source-code.d.ts +5 -0
  45. package/build/typescript/features/source-code.d.ts.map +1 -0
  46. package/build/typescript/features/system-js.d.ts +7 -0
  47. package/build/typescript/features/system-js.d.ts.map +1 -0
  48. package/build/typescript/index.d.ts +1 -3
  49. package/build/typescript/index.d.ts.map +1 -1
  50. package/package.json +5 -2
  51. package/source/app.ts +184 -122
  52. package/source/features/assets.ts +183 -0
  53. package/source/features/css.ts +91 -0
  54. package/source/{env.ts → features/env.ts} +4 -4
  55. package/source/{request-router.ts → features/request-router.ts} +3 -3
  56. package/source/{shared → features}/source-code.ts +3 -0
  57. package/source/features/system-js.ts +36 -0
  58. package/source/index.ts +0 -5
  59. /package/build/cjs/{graphql → features/graphql}/transform.cjs +0 -0
  60. /package/build/cjs/{graphql.cjs → features/graphql.cjs} +0 -0
  61. /package/build/esm/{graphql → features/graphql}/transform.mjs +0 -0
  62. /package/build/esm/{graphql.mjs → features/graphql.mjs} +0 -0
  63. /package/build/esnext/{graphql → features/graphql}/transform.esnext +0 -0
  64. /package/build/esnext/{graphql.esnext → features/graphql.esnext} +0 -0
  65. /package/source/{graphql → features/graphql}/transform.ts +0 -0
  66. /package/source/{graphql.ts → features/graphql.ts} +0 -0
package/build/esm/app.mjs CHANGED
@@ -1,172 +1,190 @@
1
1
  import * as path from 'node:path';
2
- import { MAGIC_MODULE_APP_COMPONENT, MAGIC_MODULE_REQUEST_ROUTER, MAGIC_MODULE_BROWSER_ASSETS, MAGIC_MODULE_ENTRY } from './constants.mjs';
2
+ import { MAGIC_MODULE_ENTRY, MAGIC_MODULE_APP_COMPONENT, MAGIC_MODULE_REQUEST_ROUTER, MAGIC_MODULE_BROWSER_ASSETS } from './constants.mjs';
3
3
  import { multiline } from './shared/strings.mjs';
4
- import { rollupPluginsToArray, getNodePlugins } from './shared/rollup.mjs';
4
+ import { getNodePlugins } from './shared/rollup.mjs';
5
5
  import { createMagicModulePlugin } from './shared/magic-module.mjs';
6
6
 
7
- function quiltAppBrowser({
7
+ async function quiltAppBrowser({
8
8
  app,
9
+ entry = MAGIC_MODULE_ENTRY,
9
10
  env,
10
11
  assets,
11
12
  module,
12
13
  graphql = true
13
14
  } = {}) {
14
15
  const mode = (typeof env === 'object' ? env?.mode : undefined) ?? 'production';
15
- return {
16
- name: '@quilted/app/browser',
17
- async options(originalOptions) {
18
- const newPlugins = rollupPluginsToArray(originalOptions.plugins);
19
- const newOptions = {
20
- ...originalOptions,
21
- plugins: newPlugins
22
- };
23
- const [{
24
- visualizer
25
- }, {
26
- sourceCode
27
- }, nodePlugins] = await Promise.all([import('rollup-plugin-visualizer'), import('./shared/source-code.mjs'), getNodePlugins()]);
28
- newPlugins.push(...nodePlugins);
29
- newPlugins.push(sourceCode({
16
+ const minify = assets?.minify ?? mode === 'production';
17
+ const [{
18
+ visualizer
19
+ }, {
20
+ sourceCode
21
+ }, {
22
+ css
23
+ }, {
24
+ rawAssets,
25
+ staticAssets
26
+ }, {
27
+ systemJS
28
+ }, nodePlugins] = await Promise.all([import('rollup-plugin-visualizer'), import('./features/source-code.mjs'), import('./features/css.mjs'), import('./features/assets.mjs'), import('./features/system-js.mjs'), getNodePlugins()]);
29
+ const plugins = [...nodePlugins, systemJS(), sourceCode({
30
+ mode
31
+ }), css({
32
+ minify
33
+ }), rawAssets(), staticAssets()];
34
+ if (env) {
35
+ const {
36
+ magicModuleEnv,
37
+ replaceProcessEnv
38
+ } = await import('./features/env.mjs');
39
+ if (typeof env === 'boolean') {
40
+ plugins.push(replaceProcessEnv({
30
41
  mode
31
42
  }));
32
- if (env) {
33
- const {
34
- magicModuleEnv,
35
- replaceProcessEnv
36
- } = await import('./env.mjs');
37
- if (typeof env === 'boolean') {
38
- newPlugins.push(replaceProcessEnv({
39
- mode: 'production'
40
- }));
41
- newPlugins.push(magicModuleEnv({
42
- mode: 'production'
43
- }));
44
- } else {
45
- newPlugins.push(replaceProcessEnv({
46
- mode: env.mode ?? 'production'
47
- }));
48
- newPlugins.push(magicModuleEnv({
49
- mode: 'production',
50
- ...env
51
- }));
52
- }
53
- }
54
- if (app) {
55
- newPlugins.push(magicModuleAppComponent({
56
- entry: app
57
- }));
58
- }
59
- newPlugins.push(magicModuleAppBrowserEntry(module));
60
- if (graphql) {
61
- const {
62
- graphql
63
- } = await import('./graphql.mjs');
64
- newPlugins.push(graphql({
65
- manifest: path.resolve(`manifests/graphql.json`)
66
- }));
67
- }
68
- const minify = assets?.minify ?? true;
69
- if (minify) {
70
- const {
71
- minify
72
- } = await import('rollup-plugin-esbuild');
73
- newPlugins.push(minify());
74
- }
75
- newPlugins.push(visualizer({
76
- template: 'treemap',
77
- open: false,
78
- brotliSize: true,
79
- filename: path.resolve(`reports/bundle-visualizer.html`)
43
+ plugins.push(magicModuleEnv({
44
+ mode
45
+ }));
46
+ } else {
47
+ plugins.push(replaceProcessEnv({
48
+ mode
49
+ }));
50
+ plugins.push(magicModuleEnv({
51
+ mode
80
52
  }));
81
- return newOptions;
53
+ }
54
+ }
55
+ if (app) {
56
+ plugins.push(magicModuleAppComponent({
57
+ entry: app
58
+ }));
59
+ }
60
+ plugins.push(magicModuleAppBrowserEntry(module));
61
+ if (graphql) {
62
+ const {
63
+ graphql
64
+ } = await import('./features/graphql.mjs');
65
+ plugins.push(graphql({
66
+ manifest: path.resolve(`manifests/graphql.json`)
67
+ }));
68
+ }
69
+ if (minify) {
70
+ const {
71
+ minify
72
+ } = await import('rollup-plugin-esbuild');
73
+ plugins.push(minify());
74
+ }
75
+ plugins.push(visualizer({
76
+ template: 'treemap',
77
+ open: false,
78
+ brotliSize: true,
79
+ filename: path.resolve(`reports/bundle-visualizer.html`)
80
+ }));
81
+ return {
82
+ input: entry,
83
+ plugins,
84
+ onwarn(warning, defaultWarn) {
85
+ // Removes annoying warnings for React-focused libraries that
86
+ // include 'use client' directives.
87
+ if (warning.code === 'MODULE_LEVEL_DIRECTIVE' && /['"]use client['"]/.test(warning.message)) {
88
+ return;
89
+ }
90
+ defaultWarn(warning);
82
91
  },
83
- outputOptions(originalOptions) {
84
- return {
85
- ...originalOptions,
86
- // format: isESM ? 'esm' : 'systemjs',
87
- format: 'esm',
88
- dir: path.resolve(`build/assets`),
89
- entryFileNames: `app.[hash].js`,
90
- assetFileNames: `[name].[hash].[ext]`,
91
- chunkFileNames: `[name].[hash].js`,
92
- manualChunks: createManualChunksSorter()
93
- };
92
+ output: {
93
+ // format: isESM ? 'esm' : 'systemjs',
94
+ format: 'esm',
95
+ dir: path.resolve(`build/assets`),
96
+ entryFileNames: `app.[hash].js`,
97
+ assetFileNames: `[name].[hash].[ext]`,
98
+ chunkFileNames: `[name].[hash].js`,
99
+ manualChunks: createManualChunksSorter()
94
100
  }
95
101
  };
96
102
  }
97
- function quiltAppServer({
103
+ async function quiltAppServer({
98
104
  app,
99
105
  env,
100
- graphql,
101
- entry
106
+ graphql = true,
107
+ entry = MAGIC_MODULE_ENTRY,
108
+ minify = false
102
109
  } = {}) {
103
110
  const mode = (typeof env === 'object' ? env?.mode : undefined) ?? 'production';
104
- return {
105
- name: '@quilted/app/server',
106
- async options(originalOptions) {
107
- const newPlugins = rollupPluginsToArray(originalOptions.plugins);
108
- const newOptions = {
109
- ...originalOptions,
110
- plugins: newPlugins
111
- };
112
- const [{
113
- magicModuleRequestRouterEntry
114
- }, {
115
- sourceCode
116
- }, nodePlugins] = await Promise.all([import('./request-router.mjs'), import('./shared/source-code.mjs'), getNodePlugins()]);
117
- newPlugins.push(...nodePlugins);
118
- newPlugins.push(sourceCode({
111
+ const [{
112
+ visualizer
113
+ }, {
114
+ sourceCode
115
+ }, {
116
+ css
117
+ }, {
118
+ rawAssets,
119
+ staticAssets
120
+ }, {
121
+ magicModuleRequestRouterEntry
122
+ }, nodePlugins] = await Promise.all([import('rollup-plugin-visualizer'), import('./features/source-code.mjs'), import('./features/css.mjs'), import('./features/assets.mjs'), import('./features/request-router.mjs'), getNodePlugins()]);
123
+ const plugins = [...nodePlugins, sourceCode({
124
+ mode
125
+ }), css({
126
+ emit: false
127
+ }), rawAssets(), staticAssets({
128
+ emit: false
129
+ })];
130
+ if (env) {
131
+ const {
132
+ magicModuleEnv,
133
+ replaceProcessEnv
134
+ } = await import('./features/env.mjs');
135
+ if (typeof env === 'boolean') {
136
+ plugins.push(replaceProcessEnv({
119
137
  mode
120
138
  }));
121
- if (env) {
122
- const {
123
- magicModuleEnv,
124
- replaceProcessEnv
125
- } = await import('./env.mjs');
126
- if (typeof env === 'boolean') {
127
- newPlugins.push(replaceProcessEnv({
128
- mode
129
- }));
130
- newPlugins.push(magicModuleEnv({
131
- mode
132
- }));
133
- } else {
134
- newPlugins.push(replaceProcessEnv({
135
- mode
136
- }));
137
- newPlugins.push(magicModuleEnv({
138
- mode,
139
- ...env
140
- }));
141
- }
142
- }
143
- if (app) {
144
- newPlugins.push(magicModuleAppComponent({
145
- entry: app
146
- }));
147
- }
148
- newPlugins.push(magicModuleRequestRouterEntry());
149
- newPlugins.push(magicModuleAppRequestRouter({
150
- entry
139
+ plugins.push(magicModuleEnv({
140
+ mode
151
141
  }));
152
- if (graphql) {
153
- const {
154
- graphql
155
- } = await import('./graphql.mjs');
156
- newPlugins.push(graphql({
157
- manifest: false
158
- }));
159
- }
160
- return newOptions;
161
- },
162
- outputOptions(originalOptions) {
163
- return {
164
- ...originalOptions,
165
- // format,
166
- format: 'esm',
167
- dir: path.resolve(`build/server`),
168
- entryFileNames: 'server.js'
169
- };
142
+ } else {
143
+ plugins.push(replaceProcessEnv({
144
+ mode
145
+ }));
146
+ plugins.push(magicModuleEnv({
147
+ mode
148
+ }));
149
+ }
150
+ }
151
+ if (app) {
152
+ plugins.push(magicModuleAppComponent({
153
+ entry: app
154
+ }));
155
+ }
156
+ plugins.push(magicModuleRequestRouterEntry());
157
+ plugins.push(magicModuleAppRequestRouter({
158
+ entry
159
+ }));
160
+ if (graphql) {
161
+ const {
162
+ graphql
163
+ } = await import('./features/graphql.mjs');
164
+ plugins.push(graphql({
165
+ manifest: false
166
+ }));
167
+ }
168
+ if (minify) {
169
+ const {
170
+ minify
171
+ } = await import('rollup-plugin-esbuild');
172
+ plugins.push(minify());
173
+ }
174
+ plugins.push(visualizer({
175
+ template: 'treemap',
176
+ open: false,
177
+ brotliSize: true,
178
+ filename: path.resolve(`reports/bundle-visualizer.html`)
179
+ }));
180
+ return {
181
+ input: entry,
182
+ plugins,
183
+ output: {
184
+ // format: isESM ? 'esm' : 'systemjs',
185
+ format: 'esm',
186
+ dir: path.resolve(`build/server`),
187
+ entryFileNames: 'server.js'
170
188
  }
171
189
  };
172
190
  }
@@ -0,0 +1,107 @@
1
+ import * as path from 'node:path';
2
+ import { readFile } from 'node:fs/promises';
3
+ import { createHash } from 'node:crypto';
4
+ import * as mime from 'mrmime';
5
+
6
+ const QUERY_PATTERN = /\?.*$/s;
7
+ const HASH_PATTERN = /#.*$/s;
8
+ const RAW_PATTERN = /(\?|&)raw(?:&|$)/;
9
+ const DEFAULT_INLINE_LIMIT = 4096;
10
+ const DEFAULT_OUTPUT_PATTERN = '[name].[hash].[ext]';
11
+ const DEFAULT_STATIC_ASSET_EXTENSIONS = [
12
+ // images
13
+ '.png', '.jpg', '.jpeg', '.gif', '.svg', '.ico', '.webp', '.avif',
14
+ // media
15
+ '.mp4', '.webm', '.ogg', '.mp3', '.wav', '.flac', '.aac',
16
+ // fonts
17
+ '.woff', '.woff2', '.eot', '.ttf', '.otf',
18
+ // other
19
+ '.webmanifest', '.pdf', '.txt'];
20
+ function rawAssets() {
21
+ return {
22
+ name: '@quilted/raw-assets',
23
+ async load(id) {
24
+ if (id.startsWith('\0') || !RAW_PATTERN.test(id)) {
25
+ return null;
26
+ }
27
+ const moduleId = cleanModuleIdentifier(id);
28
+ this.addWatchFile(moduleId);
29
+ const file = await readFile(moduleId, {
30
+ encoding: 'utf-8'
31
+ });
32
+ return `export default ${JSON.stringify(file)}`;
33
+ }
34
+ };
35
+ }
36
+ function staticAssets({
37
+ emit = true,
38
+ baseURL = '/',
39
+ extensions = DEFAULT_STATIC_ASSET_EXTENSIONS,
40
+ inlineLimit = DEFAULT_INLINE_LIMIT,
41
+ outputPattern = DEFAULT_OUTPUT_PATTERN
42
+ } = {}) {
43
+ const assetCache = new Map();
44
+ const assetMatcher = new RegExp(`\\.(` + extensions.map(extension => extension.startsWith('.') ? extension.slice(1) : extension).join('|') + `)(\\?.*)?$`);
45
+ return {
46
+ name: '@quilted/static-assets',
47
+ async load(id) {
48
+ if (id.startsWith('\0') || !assetMatcher.test(id)) {
49
+ return null;
50
+ }
51
+ const cached = assetCache.get(id);
52
+ if (cached) {
53
+ return cached;
54
+ }
55
+ const file = cleanModuleIdentifier(id);
56
+ const content = await readFile(file);
57
+ let url;
58
+ if (!file.endsWith('.svg') && content.length < inlineLimit) {
59
+ // base64 inlined as a string
60
+ url = `data:${mime.lookup(file)};base64,${content.toString('base64')}`;
61
+ } else {
62
+ const contentHash = getHash(content);
63
+ const filename = assetFileNamesToFileName(outputPattern, file, contentHash);
64
+ url = `${baseURL.endsWith('/') ? baseURL.slice(0, -1) : baseURL}/${filename}`;
65
+ if (emit) {
66
+ this.emitFile({
67
+ name: file,
68
+ type: 'asset',
69
+ fileName: filename,
70
+ source: content
71
+ });
72
+ }
73
+ }
74
+ const source = `export default ${JSON.stringify(url)};`;
75
+ assetCache.set(id, source);
76
+ return source;
77
+ }
78
+ };
79
+ }
80
+ function assetFileNamesToFileName(pattern, file, contentHash) {
81
+ const basename = path.basename(file);
82
+ const extname = path.extname(basename);
83
+ const ext = extname.substring(1);
84
+ const name = basename.slice(0, -extname.length);
85
+ const hash = contentHash;
86
+ return pattern.replace(/\[\w+\]/g, placeholder => {
87
+ switch (placeholder) {
88
+ case '[ext]':
89
+ return ext;
90
+ case '[extname]':
91
+ return extname;
92
+ case '[hash]':
93
+ return hash;
94
+ case '[name]':
95
+ return name;
96
+ }
97
+ throw new Error(`invalid placeholder ${placeholder} in assetFileNames "${pattern}"`);
98
+ });
99
+ }
100
+ function getHash(text) {
101
+ return createHash('sha256').update(text).digest('hex').substring(0, 8);
102
+ }
103
+ function cleanModuleIdentifier(url) {
104
+ return url.replace(HASH_PATTERN, '').replace(QUERY_PATTERN, '');
105
+ }
106
+
107
+ export { rawAssets, staticAssets };
@@ -0,0 +1,69 @@
1
+ const CSS_REGEX = /\.css$/;
2
+ const CSS_MODULE_REGEX = /\.module\.css$/;
3
+ function css({
4
+ minify = true,
5
+ emit = true
6
+ }) {
7
+ const styles = new Map();
8
+ return {
9
+ name: '@quilted/css',
10
+ async transform(code, id) {
11
+ if (!CSS_REGEX.test(id)) return;
12
+ const {
13
+ transform
14
+ } = await import('lightningcss');
15
+ const transformed = transform({
16
+ filename: id,
17
+ code: new TextEncoder().encode(code),
18
+ cssModules: CSS_MODULE_REGEX.test(id),
19
+ minify: emit && minify
20
+ });
21
+ styles.set(id, new TextDecoder().decode(transformed.code));
22
+ const exports = transformed.exports ? Object.fromEntries(Object.entries(transformed.exports).map(([key, exported]) => [key, exported.name])) : undefined;
23
+ return {
24
+ code: exports ? `export default JSON.parse(${JSON.stringify(JSON.stringify(exports))})` : `export default undefined;`,
25
+ map: {
26
+ mappings: ''
27
+ },
28
+ moduleSideEffects: 'no-treeshake'
29
+ };
30
+ },
31
+ async renderChunk(_, chunk) {
32
+ if (!emit) return null;
33
+ let chunkCss = '';
34
+ for (const id of Object.keys(chunk.modules)) {
35
+ if (CSS_REGEX.test(id) && styles.has(id)) {
36
+ chunkCss += styles.get(id);
37
+ }
38
+ }
39
+ if (chunkCss.length === 0) return null;
40
+ const code = chunkCss;
41
+
42
+ // if (minify) {
43
+ // const {default: CleanCSS} = await import('clean-css');
44
+
45
+ // const cleaner = new CleanCSS({
46
+ // rebase: false,
47
+ // });
48
+
49
+ // const minified = cleaner.minify(chunkCss);
50
+
51
+ // if (minified.errors.length > 0) {
52
+ // throw minified.errors[0];
53
+ // }
54
+
55
+ // code = minified.styles;
56
+ // }
57
+
58
+ const fileHandle = this.emitFile({
59
+ type: 'asset',
60
+ name: `${chunk.fileName.split('.')[0]}.css`,
61
+ source: code
62
+ });
63
+ chunk.imports.push(this.getFileName(fileHandle));
64
+ return null;
65
+ }
66
+ };
67
+ }
68
+
69
+ export { css };
@@ -1,9 +1,9 @@
1
1
  import * as path from 'node:path';
2
2
  import * as fs from 'node:fs';
3
- import { MAGIC_MODULE_ENV } from './constants.mjs';
4
- import { multiline } from './shared/strings.mjs';
5
- import { smartReplace } from './shared/rollup.mjs';
6
- import { createMagicModulePlugin } from './shared/magic-module.mjs';
3
+ import { MAGIC_MODULE_ENV } from '../constants.mjs';
4
+ import { multiline } from '../shared/strings.mjs';
5
+ import { smartReplace } from '../shared/rollup.mjs';
6
+ import { createMagicModulePlugin } from '../shared/magic-module.mjs';
7
7
 
8
8
  const EMPTY_PROCESS_ENV_OBJECT = {
9
9
  'globalThis.process.env.': `({}).`,
@@ -1,6 +1,6 @@
1
- import { MAGIC_MODULE_ENTRY, MAGIC_MODULE_REQUEST_ROUTER } from './constants.mjs';
2
- import { createMagicModulePlugin } from './shared/magic-module.mjs';
3
- import { multiline } from './shared/strings.mjs';
1
+ import { MAGIC_MODULE_ENTRY, MAGIC_MODULE_REQUEST_ROUTER } from '../constants.mjs';
2
+ import { createMagicModulePlugin } from '../shared/magic-module.mjs';
3
+ import { multiline } from '../shared/strings.mjs';
4
4
 
5
5
  function magicModuleRequestRouterEntry({
6
6
  host,
@@ -7,6 +7,7 @@ function sourceCode({
7
7
  targets
8
8
  }) {
9
9
  return babel({
10
+ envName: mode,
10
11
  configFile: false,
11
12
  babelrc: false,
12
13
  presets: [require.resolve('@babel/preset-typescript'), [require.resolve('@babel/preset-react'), {
@@ -31,7 +32,11 @@ function sourceCode({
31
32
  extensions: ['.ts', '.tsx', '.mts', '.mtsx', '.js', '.jsx', '.es6', '.es', '.mjs'],
32
33
  exclude: 'node_modules/**',
33
34
  babelHelpers: 'bundled',
34
- skipPreflightCheck: true
35
+ skipPreflightCheck: true,
36
+ // Babel doesn’t like this option being set to `undefined`.
37
+ ...(targets ? {
38
+ targets
39
+ } : {})
35
40
  });
36
41
  }
37
42
 
@@ -0,0 +1,33 @@
1
+ import { readFile } from 'node:fs/promises';
2
+ import { createRequire } from 'node:module';
3
+
4
+ function systemJS({
5
+ minify = false
6
+ } = {}) {
7
+ return {
8
+ name: '@quilted/system-js',
9
+ async renderChunk(_, chunk, options) {
10
+ if (options.format !== 'system' || !chunk.isEntry) return null;
11
+ const require = createRequire(import.meta.url);
12
+ const systemjs = minify ? require.resolve('systemjs/dist/s.min.js') : require.resolve('systemjs/dist/s.js');
13
+
14
+ // We write the systemjs loader to a dedicated file, and we make it the
15
+ // "first import" of the chunk so that it is the first file listed in
16
+ // the manifest.
17
+ const fileHandle = this.emitFile({
18
+ type: 'asset',
19
+ name: 'loader.js',
20
+ source: (await readFile(systemjs, {
21
+ encoding: 'utf8'
22
+ })).replace(
23
+ // Remove the source map comment, if it is present, because we don’t upload the
24
+ // sourcemap for this file.
25
+ /\n?[/][/]# sourceMappingURL=s.*\.map\n?$/, '')
26
+ });
27
+ chunk.imports.unshift(this.getFileName(fileHandle));
28
+ return null;
29
+ }
30
+ };
31
+ }
32
+
33
+ export { systemJS };
@@ -1,3 +1 @@
1
- export { magicModuleEnv } from './env.mjs';
2
- export { magicModuleAppBrowserEntry, magicModuleAppComponent, magicModuleAppRequestRouter, quiltAppBrowser, quiltAppServer } from './app.mjs';
3
- export { magicModuleRequestRouterEntry } from './request-router.mjs';
1
+ export { quiltAppBrowser, quiltAppServer } from './app.mjs';
@@ -26,8 +26,5 @@ async function getNodePlugins() {
26
26
  // exportConditions,
27
27
  }), commonjs(), json()];
28
28
  }
29
- function rollupPluginsToArray(plugins) {
30
- return Array.isArray(plugins) ? [...plugins] : plugins ? [plugins] : [];
31
- }
32
29
 
33
- export { getNodePlugins, rollupPluginsToArray, smartReplace };
30
+ export { getNodePlugins, smartReplace };