Skip to content

Instantly share code, notes, and snippets.

@muuvmuuv
Last active July 5, 2021 21:14
Show Gist options
  • Save muuvmuuv/eeb98a4fd564dd30b3f32629f636af26 to your computer and use it in GitHub Desktop.
Save muuvmuuv/eeb98a4fd564dd30b3f32629f636af26 to your computer and use it in GitHub Desktop.
Prepare your Angular application with example data without deploying it to production
import { Storage } from '@capacitor/storage'
import * as ME from 'src/data/me.json'
import { STORAGE_KEY_ME_DATA } from './app/models/auth'
/**
* Prepare the application for development by pushing some example
* data into the cache. See {@link main.ts} for implementation details.
*/
export async function init() {
await Storage.set({
key: STORAGE_KEY_ME_DATA,
value: JSON.stringify(ME),
})
}
import { enableProdMode } from '@angular/core'
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'
import { AppModule } from './app/app.module'
import { environment } from './environments/environment'
if (environment.production) {
enableProdMode()
}
if (!environment.production) {
import('./angular-example-data').then((x) => x.init())
}
platformBrowserDynamic()
.bootstrapModule(AppModule)
.then(() => console.info(`Bootstrap success 🎱`))
.catch((error: unknown) => {
console.error('Bootstrap', error)
})
const webpack = require('webpack')
module.exports = async (config, argv) => {
process.env.NODE_ENV = process.env.NODE_ENV || config.mode || argv.mode || 'development'
//
// Ignore our dev example data script.
//
config.plugins.push(
new webpack.IgnorePlugin({
resourceRegExp: /^\.\/angular-example-data$/,
})
)
return config
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment