Skip to content

Commit

Permalink
Merge pull request #746 from vector-im/madlittlemods/assets-path-for-…
Browse files Browse the repository at this point in the history
…assets

Import SDK assets from the `assets/` directory
  • Loading branch information
bwindels committed Jul 4, 2022
2 parents bb923b8 + fd3a0f0 commit fba3275
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
4 changes: 2 additions & 2 deletions doc/SDK.md
Expand Up @@ -48,8 +48,8 @@ const assetPaths = {
wasmBundle: olmJsPath
}
};
import "hydrogen-view-sdk/theme-element-light.css";
// OR import "hydrogen-view-sdk/theme-element-dark.css";
import "hydrogen-view-sdk/assets/theme-element-light.css";
// OR import "hydrogen-view-sdk/assets/theme-element-dark.css";

async function main() {
const app = document.querySelector<HTMLDivElement>('#app')!
Expand Down
2 changes: 1 addition & 1 deletion scripts/sdk/test/esm-entry.ts
Expand Up @@ -13,7 +13,7 @@ const assetPaths = {
wasmBundle: olmJsPath
}
};
import "hydrogen-view-sdk/theme-element-light.css";
import "hydrogen-view-sdk/assets/theme-element-light.css";

console.log('hydrogenViewSdk', hydrogenViewSdk);
console.log('assetPaths', assetPaths);
Expand Down
2 changes: 1 addition & 1 deletion scripts/sdk/test/test-sdk-in-commonjs-env.js
Expand Up @@ -6,7 +6,7 @@ const hydrogenViewSdk = require('hydrogen-view-sdk');
// Worker
require.resolve('hydrogen-view-sdk/main.js');
// Styles
require.resolve('hydrogen-view-sdk/theme-element-light.css');
require.resolve('hydrogen-view-sdk/assets/theme-element-light.css');
// Can access files in the assets/* directory
require.resolve('hydrogen-view-sdk/assets/main.js');

Expand Down
8 changes: 5 additions & 3 deletions vite.sdk-assets-config.js
Expand Up @@ -3,8 +3,9 @@ const mergeOptions = require('merge-options');
const themeBuilder = require("./scripts/build-plugins/rollup-plugin-build-themes");
const {commonOptions, compiledVariables} = require("./vite.common-config.js");

// These paths will be saved without their hash so they havea consisent path to
// reference
// These paths will be saved without their hash so they have a consisent path
// that we can reference in our `package.json` `exports`. And so people can import
// them with a consistent path.
const pathsToExport = [
"main.js",
"download-sandbox.html",
Expand All @@ -21,7 +22,8 @@ export default mergeOptions(commonOptions, {
output: {
assetFileNames: (chunkInfo) => {
// Get rid of the hash so we can consistently reference these
// files in our `package.json` `exports`
// files in our `package.json` `exports`. And so people can
// import them with a consistent path.
if(pathsToExport.includes(path.basename(chunkInfo.name))) {
return "assets/[name].[ext]";
}
Expand Down

0 comments on commit fba3275

Please sign in to comment.