Skip to content

Commit

Permalink
Allow data urls (#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
tjcouch-sil authored Nov 2, 2023
2 parents 0e6f89c + 220972b commit 8e0d7e0
Show file tree
Hide file tree
Showing 2 changed files with 127 additions and 0 deletions.
108 changes: 108 additions & 0 deletions src/webpack-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,112 @@ declare module '*.css' {

// #endregion

// #region images

/**
* Load images as data uris
*
* Note: it is generally advised to use the `papi-extension:` protocol to load assets
*/
declare module '*.png' {
const content: string;
export default content;
}

/**
* Load images as data uris
*
* Note: it is generally advised to use the `papi-extension:` protocol to load assets
*/
declare module '*.svg' {
const content: string;
export default content;
}

/**
* Load images as data uris
*
* Note: it is generally advised to use the `papi-extension:` protocol to load assets
*/
declare module '*.jpg' {
const content: string;
export default content;
}

/**
* Load images as data uris
*
* Note: it is generally advised to use the `papi-extension:` protocol to load assets
*/
declare module '*.jpeg' {
const content: string;
export default content;
}

/**
* Load images as data uris
*
* Note: it is generally advised to use the `papi-extension:` protocol to load assets
*/
declare module '*.gif' {
const content: string;
export default content;
}

// #endregion

// #region fonts

/**
* Load fonts as data uris
*
* Note: it is generally advised to use the `papi-extension:` protocol to load assets
*/
declare module '*.woff' {
const content: string;
export default content;
}

/**
* Load fonts as data uris
*
* Note: it is generally advised to use the `papi-extension:` protocol to load assets
*/
declare module '*.woff2' {
const content: string;
export default content;
}

/**
* Load fonts as data uris
*
* Note: it is generally advised to use the `papi-extension:` protocol to load assets
*/
declare module '*.eot' {
const content: string;
export default content;
}

/**
* Load fonts as data uris
*
* Note: it is generally advised to use the `papi-extension:` protocol to load assets
*/
declare module '*.ttf' {
const content: string;
export default content;
}

/**
* Load fonts as data uris
*
* Note: it is generally advised to use the `papi-extension:` protocol to load assets
*/
declare module '*.otf' {
const content: string;
export default content;
}

// #endregion

// #endregion
19 changes: 19 additions & 0 deletions webpack/webpack.config.base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,25 @@ const configBase: webpack.Configuration = {
'sass-loader',
],
},
/** Load images as data uris
*
* Note: it is generally advised to use the `papi-extension:` protocol to load assets
*/
// https://webpack.js.org/guides/asset-management/#loading-images
{
test: /\.(png|svg|jpg|jpeg|gif)$/i,
type: 'asset/inline',
},
/**
* Load fonts as data uris
*
* Note: it is generally advised to use the `papi-extension:` protocol to load assets
*/
// https://webpack.js.org/guides/asset-management/#loading-fonts
{
test: /\.(woff|woff2|eot|ttf|otf)$/i,
type: 'asset/inline',
},
/**
* Import files with no transformation as strings with "./file?raw"
*/
Expand Down

0 comments on commit 8e0d7e0

Please sign in to comment.