From 205352e0466d95611b1e2504413fffe40d3b3ead Mon Sep 17 00:00:00 2001 From: Owen Buckley Date: Tue, 30 Jul 2024 21:06:53 -0400 Subject: [PATCH] enhancement/issue 923 real production import attributes (#1259) * WIP real production import attributes * restore all test cases to passing * all test cases and website building correctly * rollup resolveId refactoring * rename rollup configs to be more explicit * refine test cases * clean up console logs and TODOs * add import attributes to the docs * handle base path for bundled import attributes references --- packages/cli/src/config/rollup.config.js | 159 ++++++++++++++++-- packages/cli/src/lifecycles/bundle.js | 14 +- .../plugins/resource/plugin-standard-css.js | 23 +-- .../loaders-build.import-attributes.spec.js | 23 ++- ...-build.prerender-import-attributes.spec.js | 21 ++- ...erve.default.ssr-import-attributes.spec.js | 6 +- .../build.matchers/build.matchers.spec.js | 2 +- .../test/cases/default/default.spec.js | 3 +- .../test/cases/default/greenwood.config.js | 1 - www/pages/docs/css-and-images.md | 36 +++- 10 files changed, 233 insertions(+), 55 deletions(-) diff --git a/packages/cli/src/config/rollup.config.js b/packages/cli/src/config/rollup.config.js index 7771d1141..6b49844a7 100644 --- a/packages/cli/src/config/rollup.config.js +++ b/packages/cli/src/config/rollup.config.js @@ -12,7 +12,10 @@ function cleanRollupId(id) { return id.replace('\x00', '').replace('?commonjs-proxy', ''); } -function greenwoodResourceLoader (compilation) { +// ConstructableStylesheets, JSON Modules +const externalizedResources = ['css', 'json']; + +function greenwoodResourceLoader (compilation, browser = false) { const resourcePlugins = compilation.config.plugins.filter((plugin) => { return plugin.type === 'resource'; }).map((plugin) => { @@ -21,16 +24,28 @@ function greenwoodResourceLoader (compilation) { return { name: 'greenwood-resource-loader', - async resolveId(id) { - const normalizedId = cleanRollupId(id); // idUrl.pathname; - const { projectDirectory, userWorkspace } = compilation.context; - - if (normalizedId.startsWith('.') && !normalizedId.startsWith(projectDirectory.pathname)) { + async resolveId(id, importer) { + const normalizedId = cleanRollupId(id); + const { userWorkspace } = compilation.context; + + // check for non bare paths and resolve them to the user's workspace + // or Greenwood's scratch dir, like when bundling inline