Skip to content

Commit

Permalink
update inline strategy (#254)
Browse files Browse the repository at this point in the history
* update inline strategy

fixes issue #253
  • Loading branch information
patricklx committed Aug 1, 2023
1 parent 65701f0 commit 99c2d74
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 18 deletions.
13 changes: 10 additions & 3 deletions packages/ember-svg-jar/addon/helpers/svg-jar.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
import { helper } from '@ember/component/helper';
import makeSVG from 'ember-svg-jar/utils/make-svg';
import assets from '../inlined';
import { importSync } from '@embroider/macros';

function getInlineAsset(assetId) {
let result = null;
try {
return assets[assetId]().default;
result = require(`ember-svg-jar/inlined/${assetId}`).default;
} catch (err) {
return null;
// skip
}
try {
result = importSync(`../inlined/${assetId}`).default;
} catch (err) {
// skip
}
return result;
}

export function svgJar(assetId, svgAttrs) {
Expand Down
13 changes: 0 additions & 13 deletions packages/ember-svg-jar/lib/inline-packer.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,6 @@ class InlinePacker extends CachingWriter {

assets.push(jsName);
});

// Generate index.js that contains methods to import each asset
const contents = `import { importSync } from '@embroider/macros';
const obj = {
${assets
.map(asset => {
const assetName = asset.replace(/'/g, "\\'");
return `['${assetName}']: function() { return importSync('./${assetName}'); }`;
})
.join(',\n')}
}; export default obj;`;

saveToFile(path.join(outputPath, `index.js`), contents);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ describe('InlinePacker', function () {
'export default {"content":"<path d=\\"foo\\"/>","attrs":{"viewBox":"0 0 1 1"}}',
'bar.js':
'export default {"content":"<path d=\\"bar\\"/>","attrs":{"height":"10px","viewBox":"0 0 2 2"}}',
'index.js':
"import { importSync } from '@embroider/macros';\n const obj = {\n ['apost\\'rophe']: function() { return importSync('./apost\\'rophe'); },\n['bar']: function() { return importSync('./bar'); },\n['foo']: function() { return importSync('./foo'); }\n }; export default obj;",
},
};

Expand Down

0 comments on commit 99c2d74

Please sign in to comment.