{"id":15671446,"url":"https://github.com/egoist/aot-loader","last_synced_at":"2025-05-06T20:25:06.417Z","repository":{"id":45275057,"uuid":"134801955","full_name":"egoist/aot-loader","owner":"egoist","description":"Load and pre-evaluate code at compile time","archived":false,"fork":false,"pushed_at":"2021-12-25T14:32:14.000Z","size":59,"stargazers_count":16,"open_issues_count":2,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-30T20:02:12.861Z","etag":null,"topics":["aot","babel","pre-evaluate","webpack"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/egoist.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-05-25T04:07:34.000Z","updated_at":"2020-04-14T14:51:05.000Z","dependencies_parsed_at":"2022-09-26T16:21:17.198Z","dependency_job_id":null,"html_url":"https://github.com/egoist/aot-loader","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/egoist%2Faot-loader","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/egoist%2Faot-loader/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/egoist%2Faot-loader/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/egoist%2Faot-loader/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/egoist","download_url":"https://codeload.github.com/egoist/aot-loader/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252762883,"owners_count":21800391,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aot","babel","pre-evaluate","webpack"],"created_at":"2024-10-03T15:02:26.218Z","updated_at":"2025-05-06T20:25:06.397Z","avatar_url":"https://github.com/egoist.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# aot-loader\n\n[![NPM version](https://img.shields.io/npm/v/aot-loader.svg?style=flat)](https://npmjs.com/package/aot-loader) [![NPM downloads](https://img.shields.io/npm/dm/aot-loader.svg?style=flat)](https://npmjs.com/package/aot-loader) [![CircleCI](https://circleci.com/gh/egoist/aot-loader/tree/master.svg?style=shield)](https://circleci.com/gh/egoist/aot-loader/tree/master)  [![donate](https://img.shields.io/badge/$-donate-ff69b4.svg?maxAge=2592000\u0026style=flat)](https://github.com/egoist/donate) [![chat](https://img.shields.io/badge/chat-on%20discord-7289DA.svg?style=flat)](https://chat.egoist.moe)\n\n__This is similar to [babel-plugin-preval](https://github.com/kentcdodds/babel-plugin-preval) except that this is a webpack loader, which means you can write asynchronous code but import the resolved data synchronously.__\n\n__It's also similar to [val-loader](https://github.com/webpack-contrib/val-loader) but this loader returns resolved data as JSON object directly.__\n\n## Install\n\n```bash\nyarn add aot-loader --dev\n```\n\n## Usage\n\nImport a file that you intend to pre-evaluate:\n\n📝 __entry.js__:\n\n```js\nimport data from './data?aot'\n\nconsole.log(data)\n```\n\n📝 __data.js__:\n\n```js\nconst axios = require('axios')\n\nmodule.exports = async () =\u003e {\n  const posts = await axios.get('http://example.com/posts.json')\n  return { posts }\n}\n```\n\nThen update your webpack config to pre-evaluate `.js` files with `?aot` query at compile time:\n\n📝 __webpack.config.js__:\n\n```js\nmodule.exports = {\n  entry: './entry.js',\n  module: {\n    rules: [\n      {\n        test: /\\.js$/,\n        enforce: 'post',\n        resourceQuery: /\\?aot$/,\n        loader: 'aot-loader'\n      },\n      // Following is optional, depending on your needs\n      {\n        test: /\\.js$/,\n        loader: 'babel-loader'\n      }\n    ]\n  }\n}\n```\n\n### Without resource query\n\n```js\nimport data from /* aot */ './data'\n// ↓↓↓ transpiled to:\nimport data from './data?aot'\n```\n\nTo achieve this, you can use the aot babel plugin in your `.babelrc`:\n\n```js\n{\n  \"plugins\": [\n    \"module:aot-loader/babel\"\n  ]\n}\n```\n\n## API\n\n### Loader options\n\n#### getData\n\n- __Type__: `(exported, context) =\u003e data || Promise\u003cdata\u003e`\n\nGet data from the exported object of the file that is being evaluated.\n\nDefault value:\n\n```js\nfunction (exported, context) {\n  return typeof exported === 'function' ? exported(context) : exported\n}\n```\n\n#### context\n\nThe `context` argument in `getData`.\n\nDefault:\n\n```js\n{\n  loader: LoaderContext\n}\n```\n\nCheck out the [LoaderContext](https://webpack.js.org/api/loaders/#the-loader-context) API.\n\n## Contributing\n\n1. Fork it!\n2. Create your feature branch: `git checkout -b my-new-feature`\n3. Commit your changes: `git commit -am 'Add some feature'`\n4. Push to the branch: `git push origin my-new-feature`\n5. Submit a pull request :D\n\n\n## Author\n\n**aot-loader** © [egoist](https://github.com/egoist), Released under the [MIT](./LICENSE) License.\u003cbr\u003e\nAuthored and maintained by egoist with help from contributors ([list](https://github.com/egoist/aot-loader/contributors)).\n\n\u003e [github.com/egoist](https://github.com/egoist) · GitHub [@egoist](https://github.com/egoist) · Twitter [@_egoistlily](https://twitter.com/_egoistlily)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fegoist%2Faot-loader","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fegoist%2Faot-loader","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fegoist%2Faot-loader/lists"}