-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[build] [sourcemap] Add external sourcemap for easier production debu…
…gging.
- Loading branch information
Showing
12 changed files
with
94 additions
and
76 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -191,3 +191,6 @@ $RECYCLE.BIN/ | |
|
||
# Windows shortcuts | ||
*.lnk | ||
|
||
# Cypres screenshots and videos | ||
cypress/screenshots |
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 was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { PluginOption, UserConfig } from 'vite'; | ||
import { dirname, resolve } from 'path'; | ||
|
||
export const minifyInlineCSS: PluginOption = { | ||
name: 'fs-minify-inline-css', | ||
transform(code, id) { | ||
// We are only minifying TypeScript and JavaScript files. | ||
if (!/\.(ts|js)$/.test(id)) { | ||
return null; | ||
} | ||
|
||
// Regex to match CSS inside template literals starting with `/*@fs-css-minify*/`. | ||
const cssRegex = /\/\*@fs-css-minify\*\/\s*`([^`]+)`/g; | ||
|
||
// Check if the code contains any CSS to minify. | ||
if (cssRegex.test(code)) { | ||
// Replace all the CSS inside template literals with minified CSS. | ||
code = code.replace(cssRegex, (_, css) => { | ||
// Just remove the new lines and spaces. | ||
css = css.replace(/\s+/g, ' ').trim(); | ||
|
||
// Return the minified CSS inside a template literal. | ||
return `\`${css}\``; | ||
}); | ||
} | ||
|
||
return { | ||
code, | ||
map: null, | ||
}; | ||
}, | ||
}; | ||
|
||
export function createConfig( | ||
entry: string, | ||
outDir: string, | ||
sourceRootDir: string | ||
): UserConfig { | ||
const iifeName = outDir.charAt(0).toUpperCase() + outDir.slice(1); | ||
|
||
return { | ||
build: { | ||
outDir: `lib/${outDir}`, | ||
target: 'es2015', | ||
lib: { | ||
entry, | ||
formats: ['iife'], | ||
// @note - The build will not expose this variable because the file itself doesn't export anything, but we just need to give it a name anyway for the tooling. | ||
name: `__FSCheckout${iifeName}Internal__`, | ||
fileName: () => `checkout.${outDir}.js`, | ||
}, | ||
sourcemap: true, | ||
rollupOptions: { | ||
output: { | ||
sourcemapPathTransform(relativeSourcePath, sourcemapPath) { | ||
// Make it start from the root. | ||
return resolve( | ||
dirname(sourcemapPath), | ||
relativeSourcePath | ||
) | ||
.replace(sourceRootDir, '') | ||
.replace('/src/', '/fs-checkout/'); | ||
}, | ||
}, | ||
}, | ||
}, | ||
plugins: [minifyInlineCSS], | ||
}; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,7 @@ | ||
import { defineConfig } from 'vite'; | ||
import { resolve } from 'path'; | ||
import { minifyInlineCSS } from './src/lib/utils/vite-plugins'; | ||
import { createConfig } from './src/lib/utils/vite'; | ||
|
||
export default defineConfig({ | ||
build: { | ||
outDir: 'lib/adapter', | ||
target: 'es2015', | ||
lib: { | ||
entry: resolve(__dirname, './src/adapter.ts'), | ||
formats: ['iife'], | ||
// @note - The build will not expose this variable because the file itself doesn't export anything, but we just need to give it a name anyway for the tooling. | ||
name: '__FSCheckoutAdapterInternal__', | ||
fileName: () => `checkout.js`, | ||
}, | ||
sourcemap: false, | ||
}, | ||
plugins: [minifyInlineCSS], | ||
}); | ||
export default defineConfig( | ||
createConfig(resolve(__dirname, './src/adapter.ts'), 'adapter', __dirname) | ||
); |
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 |
---|---|---|
@@ -1,19 +1,7 @@ | ||
import { defineConfig } from 'vite'; | ||
import { resolve } from 'path'; | ||
import { minifyInlineCSS } from './src/lib/utils/vite-plugins'; | ||
import { createConfig } from './src/lib/utils/vite'; | ||
|
||
export default defineConfig({ | ||
build: { | ||
outDir: 'lib/global', | ||
target: 'es2015', | ||
lib: { | ||
entry: resolve(__dirname, './src/global.ts'), | ||
formats: ['iife'], | ||
// @note - The build will not expose this variable because the file itself doesn't export anything, but we just need to give it a name anyway for the tooling. | ||
name: '__FSCheckoutGlobalInternal__', | ||
fileName: () => `checkout.js`, | ||
}, | ||
sourcemap: false, | ||
}, | ||
plugins: [minifyInlineCSS], | ||
}); | ||
export default defineConfig( | ||
createConfig(resolve(__dirname, './src/global.ts'), 'global', __dirname) | ||
); |
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