@quilted/rollup 0.1.3 → 0.1.5
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/CHANGELOG.md +14 -0
- package/build/cjs/app.cjs +150 -136
- package/build/cjs/features/assets.cjs +130 -0
- package/build/cjs/{env.cjs → features/env.cjs} +4 -4
- package/build/cjs/{request-router.cjs → features/request-router.cjs} +3 -3
- package/build/cjs/features/source-code.cjs +40 -0
- package/build/cjs/features/system-js.cjs +35 -0
- package/build/cjs/index.cjs +0 -7
- package/build/cjs/shared/rollup.cjs +0 -4
- package/build/esm/app.mjs +152 -138
- package/build/esm/features/assets.mjs +107 -0
- package/build/esm/{env.mjs → features/env.mjs} +4 -4
- package/build/esm/{request-router.mjs → features/request-router.mjs} +3 -3
- package/build/esm/features/source-code.mjs +38 -0
- package/build/esm/features/system-js.mjs +33 -0
- package/build/esm/index.mjs +1 -3
- package/build/esm/shared/rollup.mjs +1 -4
- package/build/esnext/app.esnext +152 -138
- package/build/esnext/features/assets.esnext +107 -0
- package/build/esnext/{env.esnext → features/env.esnext} +4 -4
- package/build/esnext/{request-router.esnext → features/request-router.esnext} +3 -3
- package/build/esnext/features/source-code.esnext +38 -0
- package/build/esnext/features/system-js.esnext +33 -0
- package/build/esnext/index.esnext +1 -3
- package/build/esnext/shared/rollup.esnext +1 -4
- package/build/tsconfig.tsbuildinfo +1 -1
- package/build/typescript/app.d.ts +32 -144
- package/build/typescript/app.d.ts.map +1 -1
- package/build/typescript/features/assets.d.ts +13 -0
- package/build/typescript/features/assets.d.ts.map +1 -0
- package/build/typescript/features/css.d.ts +16 -0
- package/build/typescript/features/css.d.ts.map +1 -0
- package/build/typescript/features/env.d.ts +57 -0
- package/build/typescript/features/env.d.ts.map +1 -0
- package/build/typescript/features/graphql/transform.d.ts +17 -0
- package/build/typescript/features/graphql/transform.d.ts.map +1 -0
- package/build/typescript/features/graphql.d.ts +6 -0
- package/build/typescript/features/graphql.d.ts.map +1 -0
- package/build/typescript/features/request-router.d.ts +15 -0
- package/build/typescript/features/request-router.d.ts.map +1 -0
- package/build/typescript/features/source-code.d.ts +5 -0
- package/build/typescript/features/source-code.d.ts.map +1 -0
- package/build/typescript/features/system-js.d.ts +7 -0
- package/build/typescript/features/system-js.d.ts.map +1 -0
- package/build/typescript/index.d.ts +1 -3
- package/build/typescript/index.d.ts.map +1 -1
- package/build/typescript/shared/source-code.d.ts +5 -0
- package/build/typescript/shared/source-code.d.ts.map +1 -0
- package/package.json +15 -2
- package/source/app.ts +173 -118
- package/source/features/assets.ts +183 -0
- package/source/features/css.ts +91 -0
- package/source/{env.ts → features/env.ts} +4 -4
- package/source/{request-router.ts → features/request-router.ts} +3 -3
- package/source/features/source-code.ts +64 -0
- package/source/features/system-js.ts +36 -0
- package/source/index.ts +0 -5
- /package/build/cjs/{graphql → features/graphql}/transform.cjs +0 -0
- /package/build/cjs/{graphql.cjs → features/graphql.cjs} +0 -0
- /package/build/esm/{graphql → features/graphql}/transform.mjs +0 -0
- /package/build/esm/{graphql.mjs → features/graphql.mjs} +0 -0
- /package/build/esnext/{graphql → features/graphql}/transform.esnext +0 -0
- /package/build/esnext/{graphql.esnext → features/graphql.esnext} +0 -0
- /package/source/{graphql → features/graphql}/transform.ts +0 -0
- /package/source/{graphql.ts → features/graphql.ts} +0 -0
package/build/esm/app.mjs
CHANGED
|
@@ -1,160 +1,174 @@
|
|
|
1
1
|
import * as path from 'node:path';
|
|
2
|
-
import { MAGIC_MODULE_APP_COMPONENT, MAGIC_MODULE_REQUEST_ROUTER, MAGIC_MODULE_BROWSER_ASSETS
|
|
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 {
|
|
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
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}));
|
|
38
|
-
} else {
|
|
39
|
-
newPlugins.push(replaceProcessEnv({
|
|
40
|
-
mode: env.mode ?? 'production'
|
|
41
|
-
}));
|
|
42
|
-
newPlugins.push(magicModuleEnv({
|
|
43
|
-
mode: 'production',
|
|
44
|
-
...env
|
|
45
|
-
}));
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
if (app) {
|
|
49
|
-
newPlugins.push(magicModuleAppComponent({
|
|
50
|
-
entry: app
|
|
51
|
-
}));
|
|
52
|
-
}
|
|
53
|
-
newPlugins.push(magicModuleAppBrowserEntry(module));
|
|
54
|
-
if (graphql) {
|
|
55
|
-
const {
|
|
56
|
-
graphql
|
|
57
|
-
} = await import('./graphql.mjs');
|
|
58
|
-
newPlugins.push(graphql({
|
|
59
|
-
manifest: path.resolve(`manifests/graphql.json`)
|
|
60
|
-
}));
|
|
61
|
-
}
|
|
62
|
-
const minify = assets?.minify ?? true;
|
|
63
|
-
if (minify) {
|
|
64
|
-
const {
|
|
65
|
-
minify
|
|
66
|
-
} = await import('rollup-plugin-esbuild');
|
|
67
|
-
newPlugins.push(minify());
|
|
68
|
-
}
|
|
69
|
-
newPlugins.push(visualizer({
|
|
70
|
-
template: 'treemap',
|
|
71
|
-
open: false,
|
|
72
|
-
brotliSize: true,
|
|
73
|
-
filename: path.resolve(`reports/bundle-visualizer.html`)
|
|
15
|
+
const mode = (typeof env === 'object' ? env?.mode : undefined) ?? 'production';
|
|
16
|
+
const minify = assets?.minify ?? true;
|
|
17
|
+
const [{
|
|
18
|
+
visualizer
|
|
19
|
+
}, {
|
|
20
|
+
sourceCode
|
|
21
|
+
}, {
|
|
22
|
+
rawAssets,
|
|
23
|
+
staticAssets
|
|
24
|
+
}, {
|
|
25
|
+
systemJS
|
|
26
|
+
}, nodePlugins] = await Promise.all([import('rollup-plugin-visualizer'), import('./features/source-code.mjs'), import('./features/assets.mjs'), import('./features/system-js.mjs'), getNodePlugins()]);
|
|
27
|
+
const plugins = [...nodePlugins, systemJS(), sourceCode({
|
|
28
|
+
mode
|
|
29
|
+
}), rawAssets(), staticAssets()];
|
|
30
|
+
if (env) {
|
|
31
|
+
const {
|
|
32
|
+
magicModuleEnv,
|
|
33
|
+
replaceProcessEnv
|
|
34
|
+
} = await import('./features/env.mjs');
|
|
35
|
+
if (typeof env === 'boolean') {
|
|
36
|
+
plugins.push(replaceProcessEnv({
|
|
37
|
+
mode
|
|
74
38
|
}));
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
39
|
+
plugins.push(magicModuleEnv({
|
|
40
|
+
mode
|
|
41
|
+
}));
|
|
42
|
+
} else {
|
|
43
|
+
plugins.push(replaceProcessEnv({
|
|
44
|
+
mode
|
|
45
|
+
}));
|
|
46
|
+
plugins.push(magicModuleEnv({
|
|
47
|
+
mode
|
|
48
|
+
}));
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
if (app) {
|
|
52
|
+
plugins.push(magicModuleAppComponent({
|
|
53
|
+
entry: app
|
|
54
|
+
}));
|
|
55
|
+
}
|
|
56
|
+
plugins.push(magicModuleAppBrowserEntry(module));
|
|
57
|
+
if (graphql) {
|
|
58
|
+
const {
|
|
59
|
+
graphql
|
|
60
|
+
} = await import('./features/graphql.mjs');
|
|
61
|
+
plugins.push(graphql({
|
|
62
|
+
manifest: path.resolve(`manifests/graphql.json`)
|
|
63
|
+
}));
|
|
64
|
+
}
|
|
65
|
+
if (minify) {
|
|
66
|
+
const {
|
|
67
|
+
minify
|
|
68
|
+
} = await import('rollup-plugin-esbuild');
|
|
69
|
+
plugins.push(minify());
|
|
70
|
+
}
|
|
71
|
+
plugins.push(visualizer({
|
|
72
|
+
template: 'treemap',
|
|
73
|
+
open: false,
|
|
74
|
+
brotliSize: true,
|
|
75
|
+
filename: path.resolve(`reports/bundle-visualizer.html`)
|
|
76
|
+
}));
|
|
77
|
+
return {
|
|
78
|
+
input: entry,
|
|
79
|
+
plugins,
|
|
80
|
+
output: {
|
|
81
|
+
// format: isESM ? 'esm' : 'systemjs',
|
|
82
|
+
format: 'esm',
|
|
83
|
+
dir: path.resolve(`build/assets`),
|
|
84
|
+
entryFileNames: `app.[hash].js`,
|
|
85
|
+
assetFileNames: `[name].[hash].[ext]`,
|
|
86
|
+
chunkFileNames: `[name].[hash].js`,
|
|
87
|
+
manualChunks: createManualChunksSorter()
|
|
88
88
|
}
|
|
89
89
|
};
|
|
90
90
|
}
|
|
91
|
-
function quiltAppServer({
|
|
91
|
+
async function quiltAppServer({
|
|
92
92
|
app,
|
|
93
93
|
env,
|
|
94
94
|
graphql,
|
|
95
|
-
entry
|
|
95
|
+
entry = MAGIC_MODULE_ENTRY,
|
|
96
|
+
minify = false
|
|
96
97
|
} = {}) {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
} else {
|
|
122
|
-
newPlugins.push(replaceProcessEnv({
|
|
123
|
-
mode: env.mode ?? 'production'
|
|
124
|
-
}));
|
|
125
|
-
newPlugins.push(magicModuleEnv({
|
|
126
|
-
mode: 'production',
|
|
127
|
-
...env
|
|
128
|
-
}));
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
if (app) {
|
|
132
|
-
newPlugins.push(magicModuleAppComponent({
|
|
133
|
-
entry: app
|
|
134
|
-
}));
|
|
135
|
-
}
|
|
136
|
-
newPlugins.push(magicModuleRequestRouterEntry());
|
|
137
|
-
newPlugins.push(magicModuleAppRequestRouter({
|
|
138
|
-
entry
|
|
98
|
+
const mode = (typeof env === 'object' ? env?.mode : undefined) ?? 'production';
|
|
99
|
+
const [{
|
|
100
|
+
visualizer
|
|
101
|
+
}, {
|
|
102
|
+
sourceCode
|
|
103
|
+
}, {
|
|
104
|
+
rawAssets,
|
|
105
|
+
staticAssets
|
|
106
|
+
}, {
|
|
107
|
+
magicModuleRequestRouterEntry
|
|
108
|
+
}, nodePlugins] = await Promise.all([import('rollup-plugin-visualizer'), import('./features/source-code.mjs'), import('./features/assets.mjs'), import('./features/request-router.mjs'), getNodePlugins()]);
|
|
109
|
+
const plugins = [...nodePlugins, sourceCode({
|
|
110
|
+
mode
|
|
111
|
+
}), rawAssets(), staticAssets({
|
|
112
|
+
emit: false
|
|
113
|
+
})];
|
|
114
|
+
if (env) {
|
|
115
|
+
const {
|
|
116
|
+
magicModuleEnv,
|
|
117
|
+
replaceProcessEnv
|
|
118
|
+
} = await import('./features/env.mjs');
|
|
119
|
+
if (typeof env === 'boolean') {
|
|
120
|
+
plugins.push(replaceProcessEnv({
|
|
121
|
+
mode
|
|
139
122
|
}));
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
123
|
+
plugins.push(magicModuleEnv({
|
|
124
|
+
mode
|
|
125
|
+
}));
|
|
126
|
+
} else {
|
|
127
|
+
plugins.push(replaceProcessEnv({
|
|
128
|
+
mode
|
|
129
|
+
}));
|
|
130
|
+
plugins.push(magicModuleEnv({
|
|
131
|
+
mode
|
|
132
|
+
}));
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
if (app) {
|
|
136
|
+
plugins.push(magicModuleAppComponent({
|
|
137
|
+
entry: app
|
|
138
|
+
}));
|
|
139
|
+
}
|
|
140
|
+
plugins.push(magicModuleRequestRouterEntry());
|
|
141
|
+
plugins.push(magicModuleAppRequestRouter({
|
|
142
|
+
entry
|
|
143
|
+
}));
|
|
144
|
+
if (graphql) {
|
|
145
|
+
const {
|
|
146
|
+
graphql
|
|
147
|
+
} = await import('./features/graphql.mjs');
|
|
148
|
+
plugins.push(graphql({
|
|
149
|
+
manifest: false
|
|
150
|
+
}));
|
|
151
|
+
}
|
|
152
|
+
if (minify) {
|
|
153
|
+
const {
|
|
154
|
+
minify
|
|
155
|
+
} = await import('rollup-plugin-esbuild');
|
|
156
|
+
plugins.push(minify());
|
|
157
|
+
}
|
|
158
|
+
plugins.push(visualizer({
|
|
159
|
+
template: 'treemap',
|
|
160
|
+
open: false,
|
|
161
|
+
brotliSize: true,
|
|
162
|
+
filename: path.resolve(`reports/bundle-visualizer.html`)
|
|
163
|
+
}));
|
|
164
|
+
return {
|
|
165
|
+
input: entry,
|
|
166
|
+
plugins,
|
|
167
|
+
output: {
|
|
168
|
+
// format: isESM ? 'esm' : 'systemjs',
|
|
169
|
+
format: 'esm',
|
|
170
|
+
dir: path.resolve(`build/server`),
|
|
171
|
+
entryFileNames: 'server.js'
|
|
158
172
|
}
|
|
159
173
|
};
|
|
160
174
|
}
|
|
@@ -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 };
|
|
@@ -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 '
|
|
4
|
-
import { multiline } from '
|
|
5
|
-
import { smartReplace } from '
|
|
6
|
-
import { createMagicModulePlugin } from '
|
|
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 '
|
|
2
|
-
import { createMagicModulePlugin } from '
|
|
3
|
-
import { multiline } from '
|
|
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,
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { createRequire } from 'node:module';
|
|
2
|
+
import babel from '@rollup/plugin-babel';
|
|
3
|
+
|
|
4
|
+
const require = createRequire(import.meta.url);
|
|
5
|
+
function sourceCode({
|
|
6
|
+
mode,
|
|
7
|
+
targets
|
|
8
|
+
}) {
|
|
9
|
+
return babel({
|
|
10
|
+
configFile: false,
|
|
11
|
+
babelrc: false,
|
|
12
|
+
presets: [require.resolve('@babel/preset-typescript'), [require.resolve('@babel/preset-react'), {
|
|
13
|
+
runtime: 'automatic',
|
|
14
|
+
importSource: 'react',
|
|
15
|
+
development: mode === 'development'
|
|
16
|
+
}], [require.resolve('@babel/preset-env'), {
|
|
17
|
+
// @ts-expect-error This is a valid option
|
|
18
|
+
corejs: '3.15',
|
|
19
|
+
useBuiltIns: 'usage',
|
|
20
|
+
bugfixes: true,
|
|
21
|
+
shippedProposals: true,
|
|
22
|
+
// I thought I wanted this on, but if you do this, Babel
|
|
23
|
+
// stops respecting the top-level `targets` option and tries
|
|
24
|
+
// to use the targets passed to the preset directly instead.
|
|
25
|
+
ignoreBrowserslistConfig: true
|
|
26
|
+
}]],
|
|
27
|
+
plugins: [[require.resolve('@babel/plugin-proposal-decorators'), {
|
|
28
|
+
version: '2023-01'
|
|
29
|
+
}]],
|
|
30
|
+
targets,
|
|
31
|
+
extensions: ['.ts', '.tsx', '.mts', '.mtsx', '.js', '.jsx', '.es6', '.es', '.mjs'],
|
|
32
|
+
exclude: 'node_modules/**',
|
|
33
|
+
babelHelpers: 'bundled',
|
|
34
|
+
skipPreflightCheck: true
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export { sourceCode };
|
|
@@ -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 };
|
package/build/esm/index.mjs
CHANGED
|
@@ -1,3 +1 @@
|
|
|
1
|
-
export {
|
|
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,
|
|
30
|
+
export { getNodePlugins, smartReplace };
|