Skip to content

feat(config): accept multiple entrypoints for build #149

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Apr 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
200 changes: 183 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -205,14 +205,71 @@ This is the first example using JSDoc to provide type information:
```javascript
/** @type {import('azion').AzionConfig} */
const config = {
build: {},
domain: {},
origin: [],
cache: [],
rules: [],
purge: [],
networkList: [],
waf: [],
build: {
// Build configuration
bundler: 'esbuild',
entry: './src/index.js',
preset: 'react',
polyfills: true,
worker: true,
},
domain: {
name: 'example.com',
cnameAccessOnly: false,
},
origin: [
{
name: 'My Origin',
type: 'single_origin',
addresses: ['origin.example.com'],
},
],
cache: [
{
name: 'Default Cache',
browser: { maxAgeSeconds: 3600 },
edge: { maxAgeSeconds: 7200 },
},
],
rules: {
request: [
{
name: 'Example Rule',
match: 'path',
behavior: { setOrigin: { name: 'My Origin', type: 'single_origin' } },
},
],
},
purge: [
{
type: 'url',
urls: ['https://example.com/path/to/purge'],
},
],
networkList: [
{
id: 12345,
listType: 'ip_cidr',
listContent: ['10.0.0.1'],
},
],
firewall: {
name: 'My Firewall',
active: true,
rules: [
{
name: 'Block Suspicious IPs',
behavior: { deny: true },
},
],
},
waf: [
{
name: 'My WAF',
mode: 'blocking',
active: true,
},
],
};

export default config;
Expand All @@ -224,22 +281,131 @@ This is the second example using the `defineConfig` function to enforce types an
import { defineConfig } from 'azion';

const config = defineConfig({
build: {},
domain: {},
origin: [],
cache: [],
rules: [],
purge: [],
networkList: [],
waf: [],
build: {
// Advanced build configuration options
bundler: 'webpack',
entry: {
main: './src/index.js',
admin: './src/admin.js',
},
preset: {
config: {
/* custom configuration */
},
metadata: {
name: 'custom-preset',
registry: 'my-registry',
},
handler: async (event) => {
// Custom handler
return new Response('Hello World');
},
},
polyfills: true,
worker: true,
extend: (config) => {
// Customize bundler configuration
return {
...config,
// Specific configurations
};
},
memoryFS: {
injectionDirs: ['./src/inject'],
removePathPrefix: './src',
},
},
domain: {
name: 'example.com',
cnameAccessOnly: false,
cnames: ['www.example.com'],
},
origin: [
{
name: 'My Origin',
type: 'single_origin',
addresses: [
{
address: 'origin.example.com',
weight: 100,
},
],
protocolPolicy: 'https',
},
],
// Other configurations...
});

export default config;
```

Here's a more advanced example using preset customization with TypeScript:

```typescript
import { defineConfig } from 'azion';
import type { AzionBuildPreset, AzionPrebuildResult, BuildContext, BuildConfiguration } from 'azion/config';
import { Next } from 'azion/presets';

export default defineConfig({
build: {
preset: {
...Next,
config: {
...Next.config,
bundler: 'esbuild',
extend: (config) => {
config.define = {
...config.define,
'global.customFeature': 'JSON.stringify(true)',
'process.env.CUSTOM_VAR': 'JSON.stringify("value")',
};
return config;
},
},
prebuild: async (config: BuildConfiguration, ctx: BuildContext): Promise<AzionPrebuildResult> => {
// Your custom prebuild logic here
console.log('Running custom prebuild with context:', ctx);

// Return prebuild result with custom configurations
return {
filesToInject: ['./src/custom-file.js'],
injection: {
globals: {
_ENTRIES: 'window._ENTRIES = {}',
AsyncLocalStorage: 'globalThis.AsyncLocalStorage = class {}',
},
entry: '// Custom entry code\nconsole.log("Custom initialization");',
banner: '/* Custom banner comment */',
},
bundler: {
defineVars: {
__CONFIG__: JSON.stringify({ customSetting: true }),
__BUILD_METADATA__: JSON.stringify({ version: '1.0.0', buildTime: Date.now() }),
},
plugins: [],
},
};
},
postbuild: async (config: BuildConfiguration, ctx: BuildContext): Promise<void> => {
// Your custom postbuild logic here
console.log('Build completed with output:', config.baseOutputDir);
},
},
// Other build configurations
entry: './src/index.ts',
polyfills: true,
worker: true,
memoryFS: {
injectionDirs: ['./src/inject'],
removePathPrefix: './src',
},
},
// Domain, origin, and other configurations...
});
```

Read more in the [AzionConfig README](./packages/config/README.md).

## Contributing

Feel free to submit issues or pull requests to improve the functionality or documentation.
AzionDomainCollectionAzionDomainCollection
8 changes: 5 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
"format:check": "npm run prettier:check --workspaces --if-present",
"test": "npm run test --workspaces --if-present",
"download:cli": "node ./cli/scripts/download-cli.mjs",
"postinstall": "npm run download:cli",
"build": "npm run download:cli && npm run compile"
"build": "npm run compile"
},
"keywords": [
"azion",
Expand Down
1 change: 1 addition & 0 deletions packages/bundler/src/bundlers/esbuild/esbuild.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ export default {
loader: {
'.js': 'js',
},
outdir: '.',
} as BuildOptions;
Loading