@quilted/rollup 0.1.6 → 0.1.8

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/source/app.ts CHANGED
@@ -1,6 +1,8 @@
1
1
  import * as path from 'path';
2
+ import * as fs from 'fs/promises';
2
3
 
3
4
  import type {Plugin, RollupOptions, GetManualChunk} from 'rollup';
5
+ import type {AssetsBuildManifest} from '@quilted/assets';
4
6
 
5
7
  import {
6
8
  MAGIC_MODULE_ENTRY,
@@ -91,6 +93,8 @@ export interface AppBrowserAssetsOptions {
91
93
  * @default true
92
94
  */
93
95
  minify?: boolean;
96
+
97
+ baseURL?: string;
94
98
  }
95
99
 
96
100
  export async function quiltAppBrowser({
@@ -104,9 +108,11 @@ export async function quiltAppBrowser({
104
108
  const mode =
105
109
  (typeof env === 'object' ? env?.mode : undefined) ?? 'production';
106
110
  const minify = assets?.minify ?? mode === 'production';
111
+ const baseURL = assets?.baseURL ?? '/assets/';
107
112
 
108
113
  const [
109
114
  {visualizer},
115
+ {assetManifest},
110
116
  {sourceCode},
111
117
  {css},
112
118
  {rawAssets, staticAssets},
@@ -114,6 +120,7 @@ export async function quiltAppBrowser({
114
120
  nodePlugins,
115
121
  ] = await Promise.all([
116
122
  import('rollup-plugin-visualizer'),
123
+ import('@quilted/assets/rollup'),
117
124
  import('./features/source-code.ts'),
118
125
  import('./features/css.ts'),
119
126
  import('./features/assets.ts'),
@@ -123,11 +130,11 @@ export async function quiltAppBrowser({
123
130
 
124
131
  const plugins: Plugin[] = [
125
132
  ...nodePlugins,
126
- systemJS(),
133
+ systemJS({minify}),
127
134
  sourceCode({mode}),
128
- css({minify}),
135
+ css({minify, emit: true}),
129
136
  rawAssets(),
130
- staticAssets(),
137
+ staticAssets({baseURL, emit: true}),
131
138
  ];
132
139
 
133
140
  if (env) {
@@ -161,11 +168,16 @@ export async function quiltAppBrowser({
161
168
  }
162
169
 
163
170
  plugins.push(
171
+ // @ts-expect-error The plugin still depends on Rollup 3
172
+ assetManifest({
173
+ baseUrl: baseURL,
174
+ path: path.resolve(`build/manifests/assets.json`),
175
+ }),
164
176
  visualizer({
165
177
  template: 'treemap',
166
178
  open: false,
167
179
  brotliSize: true,
168
- filename: path.resolve(`reports/bundle-visualizer.html`),
180
+ filename: path.resolve(`build/reports/bundle-visualizer.html`),
169
181
  }),
170
182
  );
171
183
 
@@ -241,7 +253,7 @@ export async function quiltAppServer({
241
253
  const plugins: Plugin[] = [
242
254
  ...nodePlugins,
243
255
  sourceCode({mode}),
244
- css({emit: false}),
256
+ css({emit: false, minify}),
245
257
  rawAssets(),
246
258
  staticAssets({emit: false}),
247
259
  ];
@@ -266,6 +278,7 @@ export async function quiltAppServer({
266
278
 
267
279
  plugins.push(magicModuleRequestRouterEntry());
268
280
  plugins.push(magicModuleAppRequestRouter({entry}));
281
+ plugins.push(magicModuleAppAssetManifests());
269
282
 
270
283
  if (graphql) {
271
284
  const {graphql} = await import('./features/graphql.ts');
@@ -282,13 +295,25 @@ export async function quiltAppServer({
282
295
  template: 'treemap',
283
296
  open: false,
284
297
  brotliSize: true,
285
- filename: path.resolve(`reports/bundle-visualizer.html`),
298
+ filename: path.resolve(`build/reports/bundle-visualizer.html`),
286
299
  }),
287
300
  );
288
301
 
289
302
  return {
290
303
  input: entry,
291
304
  plugins,
305
+ onwarn(warning, defaultWarn) {
306
+ // Removes annoying warnings for React-focused libraries that
307
+ // include 'use client' directives.
308
+ if (
309
+ warning.code === 'MODULE_LEVEL_DIRECTIVE' &&
310
+ /['"]use client['"]/.test(warning.message)
311
+ ) {
312
+ return;
313
+ }
314
+
315
+ defaultWarn(warning);
316
+ },
292
317
  output: {
293
318
  // format: isESM ? 'esm' : 'systemjs',
294
319
  format: 'esm',
@@ -378,6 +403,56 @@ export function magicModuleAppBrowserEntry({
378
403
  });
379
404
  }
380
405
 
406
+ export function magicModuleAppAssetManifests() {
407
+ return createMagicModulePlugin({
408
+ name: '@quilted/magic-module/asset-manifests',
409
+ module: MAGIC_MODULE_BROWSER_ASSETS,
410
+ async source() {
411
+ const {glob} = await import('glob');
412
+
413
+ const manifestFiles = await glob('assets*.json', {
414
+ nodir: true,
415
+ absolute: true,
416
+ cwd: path.resolve(`build/manifests`),
417
+ });
418
+
419
+ const manifests = await Promise.all(
420
+ manifestFiles.map(
421
+ async (file) =>
422
+ JSON.parse(await fs.readFile(file, 'utf8')) as AssetsBuildManifest,
423
+ ),
424
+ );
425
+
426
+ manifests.sort(
427
+ (manifestA, manifestB) =>
428
+ (manifestA.priority ?? 0) - (manifestB.priority ?? 0),
429
+ );
430
+
431
+ return multiline`
432
+ import {BrowserAssetsFromManifests} from '@quilted/quilt/server';
433
+
434
+ export class BrowserAssets extends BrowserAssetsFromManifests {
435
+ constructor() {
436
+ const manifests = JSON.parse(${JSON.stringify(
437
+ JSON.stringify(manifests),
438
+ )});
439
+
440
+ // The default manifest is the last one, since it has the widest browser support.
441
+ const defaultManifest = manifests.at(-1);
442
+
443
+ super(manifests, {
444
+ defaultManifest,
445
+ cacheKey(request) {
446
+ return {};
447
+ },
448
+ });
449
+ }
450
+ }
451
+ `;
452
+ },
453
+ });
454
+ }
455
+
381
456
  const FRAMEWORK_CHUNK_NAME = 'framework';
382
457
  const POLYFILLS_CHUNK_NAME = 'polyfills';
383
458
  const VENDOR_CHUNK_NAME = 'vendor';
@@ -46,7 +46,6 @@ export function sourceCode({
46
46
  {version: '2023-01'},
47
47
  ],
48
48
  ],
49
- targets,
50
49
  extensions: [
51
50
  '.ts',
52
51
  '.tsx',
package/tsconfig.json CHANGED
@@ -6,5 +6,5 @@
6
6
  },
7
7
  "include": ["source"],
8
8
  "exclude": ["quilt.project.ts", "**/*.test.ts", "**/*.test.tsx"],
9
- "references": []
9
+ "references": [{"path": "../assets"}, {"path": "../graphql"}]
10
10
  }