MageWork

Back to home

Static Site Generator

With the native static package, you can generate a static version of any package and serve the files directly.

The site will be generated in the static/{package} folder, then you can configure the web server to use this folder as root directory.

The static package can be modified and improved for specific needs.

Command

MW_ENVIRONMENT={environment} bin/magework static build {package} {baseUrl}

If the baseUrl is missing, pages will use "/" as the base URL and the site can be served on any domain.

All files at the package root (robots.txt, favicon.ico...) will be copied to the static folder, except if ignored in the configuration.

Example

For example, if your application contains a package named acme and you want to serve it at the URL https://www.example.com:

MW_ENVIRONMENT=default bin/magework static build acme https://www.example.com

Configuration

You can create a configuration file in the package to be generated to ignore routes or files.

<?php
// packages/acme/etc/static.php

$config = [
    'acme' => [
        'static' => [
            'ignore_files' => [ // Regex only
                '/(.*)README.md$/i',
                '/(.*)CHANGELOG.md$/i',
                '/(.*)LICENCE$/i',
            ],
            'ignore_routes' => [ // Regex only
                '/\/secret.html/i',
                '/\/secret\/(.*)/i',
            ],
        ],
    ],
];