-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enhancement/issue 971 refactor bundling and optimizations (#974)
* add cloud IDE caveat to puppeteer renderer plugin readme (#967) * init commit of refactoring for script tags with a src * initial CSS optimizing * sync optimized link tags in final output * refactored for shared reources * handle inline script bundling * support serving custom resources using Greenwood plugins in Rollup configuration without needing extra rollup plugin * non resource related Rollup plugins supported * custom resource plugins and rollup plugins working together * handle empty input for Rollup * updated lock file * handle inline style tag bundling and optimizing * default optimization spec passing * refactor merging app and page templates * clarifying corrections in spec files * inline optimization config working * none optimization support * none optimization support * none and static optimization overrides * refactor html rendering and optimizing * refactoring and more CLI specs passing * add missing variable * SSR specs and optimizing resource bundling * minor refactoring and logging * resolving some plugin specs * restore develop command related GraphQL specs * custom graphql query spec * all specs passing * drop rollup plugin deps from import typescript plugin * all Greenwood commands and specs passing * restore static router with custom prerender * restore postcss-import * refactor shared resources to a Map and handle dupes * restore local packages workaround for local Rollup bundling * better monorepo Rollup facade modules detection * switch console log * remove console logging * update plugin related docs * local solution for windows support * refactor errant object assign * full cross platform URL support * fix lint * fix extra bundles when custom prerendering * clean up stale or already tracked TODOs * add nested head tag smoke tests * check for app template validation for HUD display * misc refactoring and TODOs cleanup * restore static router (again) * standardize passing correct reference for prerender scripts * clean up data-gwd-opt markers from final HTML
- Loading branch information
1 parent
43a2b2d
commit 3d0ae4b
Showing
54 changed files
with
745 additions
and
1,147 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import fs from 'fs'; | ||
import { hashString } from '../lib/hashing-utils.js'; | ||
import path from 'path'; | ||
import { pathToFileURL } from 'url'; | ||
|
||
function modelResource(context, type, src = undefined, contents = undefined, optimizationAttr = undefined, rawAttributes = undefined) { | ||
const { projectDirectory, scratchDir, userWorkspace } = context; | ||
const extension = type === 'script' ? 'js' : 'css'; | ||
const windowsDriveRegex = /\/[a-zA-Z]{1}:\//; | ||
let sourcePathURL; | ||
|
||
if (src) { | ||
sourcePathURL = src.indexOf('/node_modules') === 0 | ||
? pathToFileURL(path.join(projectDirectory, src)) // TODO (good first issue) get "real" location of node modules | ||
: pathToFileURL(path.join(userWorkspace, src.replace(/\.\.\//g, '').replace('./', ''))); | ||
|
||
contents = fs.readFileSync(sourcePathURL, 'utf-8'); | ||
} else { | ||
const scratchFileName = hashString(contents); | ||
|
||
sourcePathURL = pathToFileURL(path.join(scratchDir, `${scratchFileName}.${extension}`)); | ||
fs.writeFileSync(sourcePathURL, contents); | ||
} | ||
|
||
// TODO (good first issue) handle for Windows adding extra / in front of drive letter for whatever reason :( | ||
// e.g. turn /C:/... -> C:/... | ||
// and also URL is readonly in NodeJS?? | ||
if (windowsDriveRegex.test(sourcePathURL.pathname)) { | ||
const driveMatch = sourcePathURL.pathname.match(windowsDriveRegex)[0]; | ||
|
||
sourcePathURL = { | ||
...sourcePathURL, | ||
pathname: sourcePathURL.pathname.replace(driveMatch, driveMatch.replace('/', '')), | ||
href: sourcePathURL.href.replace(driveMatch, driveMatch.replace('/', '')) | ||
}; | ||
} | ||
|
||
return { | ||
src, // if <script src="..."></script> or <link href="..."></link> | ||
sourcePathURL, // src as a URL | ||
type, | ||
contents, | ||
optimizedFileName: undefined, | ||
optimizedFileContents: undefined, | ||
optimizationAttr, | ||
rawAttributes | ||
}; | ||
} | ||
|
||
export { modelResource }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.