All Projects → egoist → aot-loader

egoist / aot-loader

Licence: MIT license
Load and pre-evaluate code at compile time

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to aot-loader

Ngx Cache
Cache utility for Angular
Stars: ✭ 144 (+800%)
Mutual labels:  aot
Angularfire Lite
⚡️ Lightweight library to use Firebase API 🔥 with Angular
Stars: ✭ 245 (+1431.25%)
Mutual labels:  aot
angular2-pokedex
A Pokedex built on Angular with AoT, Tree Shaking, Rollup and TypeScript
Stars: ✭ 34 (+112.5%)
Mutual labels:  aot
Wasm Micro Runtime
WebAssembly Micro Runtime (WAMR)
Stars: ✭ 2,440 (+15150%)
Mutual labels:  aot
Angular Awesome List
Список ресурсов по Angular на русском
Stars: ✭ 224 (+1300%)
Mutual labels:  aot
vox
Vox language compiler. AOT / JIT / Linker. Zero dependencies
Stars: ✭ 288 (+1700%)
Mutual labels:  aot
Ng2 Smart Table
Angular Smart Data Table component
Stars: ✭ 1,590 (+9837.5%)
Mutual labels:  aot
ng-seed
Simple Angular seed project with commonly used features.
Stars: ✭ 12 (-25%)
Mutual labels:  aot
Ts Llvm
TypeScript to LLVM compiler (abandoned)
Stars: ✭ 230 (+1337.5%)
Mutual labels:  aot
example-app
Example app showcasing fulls1z3's Angular libraries
Stars: ✭ 27 (+68.75%)
Mutual labels:  aot
Localize Router
An implementation of routes localisation for Angular
Stars: ✭ 177 (+1006.25%)
Mutual labels:  aot
Angular Seed Advanced
Advanced Angular seed project with support for ngrx/store, ngrx/effects, ngx-translate, angulartics2, lodash, NativeScript (*native* mobile), Electron (Mac, Windows and Linux desktop) and more.
Stars: ✭ 2,279 (+14143.75%)
Mutual labels:  aot
angular2-aot-webpack
Angular AOT (Ahead Of Time) offline compilation example with Webpack
Stars: ✭ 317 (+1881.25%)
Mutual labels:  aot
Ngx Currency
📦 Currency mask module for Angular
Stars: ✭ 161 (+906.25%)
Mutual labels:  aot
transonic
🚀 Make your Python code fly at transonic speeds!
Stars: ✭ 93 (+481.25%)
Mutual labels:  aot
Ngx Config
Configuration utility for Angular
Stars: ✭ 135 (+743.75%)
Mutual labels:  aot
NatsuLang
No description or website provided.
Stars: ✭ 96 (+500%)
Mutual labels:  aot
wasp
🐝 Wasp : Wasm programming (language)
Stars: ✭ 93 (+481.25%)
Mutual labels:  aot
WinFormsComInterop
ComWrappers required to run NativeAOT and WinForms
Stars: ✭ 54 (+237.5%)
Mutual labels:  aot
aot
Russian morphology for Java
Stars: ✭ 41 (+156.25%)
Mutual labels:  aot

aot-loader

NPM version NPM downloads CircleCI donate chat

This is similar to babel-plugin-preval except that this is a webpack loader, which means you can write asynchronous code but import the resolved data synchronously.

It's also similar to val-loader but this loader returns resolved data as JSON object directly.

Install

yarn add aot-loader --dev

Usage

Import a file that you intend to pre-evaluate:

📝 entry.js:

import data from './data?aot'

console.log(data)

📝 data.js:

const axios = require('axios')

module.exports = async () => {
  const posts = await axios.get('http://example.com/posts.json')
  return { posts }
}

Then update your webpack config to pre-evaluate .js files with ?aot query at compile time:

📝 webpack.config.js:

module.exports = {
  entry: './entry.js',
  module: {
    rules: [
      {
        test: /\.js$/,
        enforce: 'post',
        resourceQuery: /\?aot$/,
        loader: 'aot-loader'
      },
      // Following is optional, depending on your needs
      {
        test: /\.js$/,
        loader: 'babel-loader'
      }
    ]
  }
}

Without resource query

import data from /* aot */ './data'
// ↓↓↓ transpiled to:
import data from './data?aot'

To achieve this, you can use the aot babel plugin in your .babelrc:

{
  "plugins": [
    "module:aot-loader/babel"
  ]
}

API

Loader options

getData

  • Type: (exported, context) => data || Promise<data>

Get data from the exported object of the file that is being evaluated.

Default value:

function (exported, context) {
  return typeof exported === 'function' ? exported(context) : exported
}

context

The context argument in getData.

Default:

{
  loader: LoaderContext
}

Check out the LoaderContext API.

Contributing

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request :D

Author

aot-loader © egoist, Released under the MIT License.
Authored and maintained by egoist with help from contributors (list).

github.com/egoist · GitHub @egoist · Twitter @_egoistlily

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].