Last active
July 27, 2020 18:35
-
-
Save drwpow/967d24a95fd39b48c20ba2711b7d31fc to your computer and use it in GitHub Desktop.
Snowpacker plugin
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
// Example of using require.context() plugin | |
// note: this will run on every `.js` file | |
module.exports = () => ({ | |
name: 'my awesome plugin', | |
async transform({ | |
extension, // the file extension | |
contents // JS code | |
}) { | |
if (extension !== '.js') return; // if not JS, ignore | |
const context = require.context('./controllers'); // grab context | |
const imports = myFunctionToGenerateImportsFromContext(context); // TODO: generate the necessary import statements | |
return `${imports}${contents}`; // final code with imports injected at top | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment