Created
December 2, 2021 10:46
-
-
Save lifeart/f493b48f227cf9566b1f41221296f1bb to your computer and use it in GitHub Desktop.
Ember-auto-import chunk recorder (in-repo-addon)
This file contains hidden or 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
'use strict'; | |
// eslint-disable-next-line node/no-extraneous-require | |
const { MergeTrees } = require('broccoli-merge-trees'); | |
// eslint-disable-next-line node/no-extraneous-require | |
const Plugin = require('broccoli-plugin'); | |
const fs = require('fs'); | |
const path = require('path'); | |
class ChunksWriter extends Plugin { | |
constructor(inputNodes, options = {}) { | |
super(inputNodes, { | |
annotation: options.annotation, | |
// see `options` in the below README to see a full list of constructor options | |
}); | |
this.inserter = options.inserter; | |
} | |
build() { | |
const content = JSON.stringify(this.inserter.categorizeChunks(), null, 2); | |
fs.writeFileSync( | |
path.join(this.outputPath, 'chunks.json'), | |
content, | |
'utf8' | |
); | |
} | |
} | |
module.exports = { | |
name: require('./package').name, | |
isDevelopingAddon() { | |
return true; | |
}, | |
postprocessTree(which, tree) { | |
if (which === 'all') { | |
if (!tree.inputNodes) { | |
throw new Error( | |
'Unknown build tree configuration, this addon should follow exactly after ember-auto-import' | |
); | |
} | |
const inserter = tree.inputNodes.find( | |
(node) => node._name === 'Inserter' | |
); | |
const chunkWriterInstance = new ChunksWriter(['app'], { inserter }); | |
return new MergeTrees([tree, chunkWriterInstance]); | |
} | |
return tree; | |
}, | |
}; |
This file contains hidden or 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
{ | |
"name": "auto-hook", | |
"keywords": [ | |
"ember-addon" | |
], | |
"ember-addon": { | |
"after": "ember-auto-import", | |
"before": "broccoli-asset-rev" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I've done something similar using the same approach (using Inserter):
https://gist.github.com/nag5000/fb55655fb9eb99c28226984048a984f0
<script>
transforms when usinginsertScriptsAt
slots