Home Arrow Icon Knowledge base Arrow Icon Global Arrow Icon Can I use Twill's Vue CLI features with Laravel Sail


Can I use Twill's Vue CLI features with Laravel Sail


Yes, Twill's Vue CLI features can be used with Laravel Sail. Twill is designed to integrate seamlessly with Laravel, including environments managed with Laravel Sail. Laravel Sail is a lightweight command-line interface that works as a Docker development environment for Laravel applications, making it compatible with Twill's Vue CLI tooling.

To use Twill's Vue CLI features within Laravel Sail, the general process involves several steps:

1. Installation of Twill: You begin by installing Twill into your Laravel application. This typically involves running Composer commands like `composer require area17/twill:"^3.0"` to add Twill as a dependency and then running the installation Artisan command `php artisan twill:install`. This sets up Twill inside your Laravel project and its associated UI components, which are built with Vue.js.

2. Set Up Laravel Sail: Laravel Sail needs to be configured properly in your Laravel project. This includes having a `docker-compose.yml` file at your project root and running `./vendor/bin/sail up` to start the Docker containers that provide PHP, MySQL, Node, and other services. Laravel Sail essentially serves as your lightweight containerized development environment.

3. Running Vue CLI Commands Through Sail: Once both Twill and Sail are set up, you can execute Twill's Vue CLI commands inside the Sail environment using Sail's wrapper syntax. Instead of running npm or yarn commands directly on your host machine, you run them through Sail like so:
- `./vendor/bin/sail npm run dev` to start the Vue hot-reload development server.
- `./vendor/bin/sail npm run build` to compile the Vue assets for production.
- `./vendor/bin/sail npm run lint` to lint your Vue.js code as per your setup.

This way, the Vue CLI commands operate inside the Docker container, leveraging the container's environment where Node.js and npm are installed and managed.

4. Using and Customizing Twill's Vue Components: Twill's UI is composed of Vue components, which you can use as-is or extend for your own dashboards and modules. With Sail running the environment, you can build, modify, and test these components while benefiting from container consistency.

5. Additional Configuration Considerations: Twill requires certain environment versions (for example, PHP 8.0+, Laravel 9.x to 11.x, npm 5.7+ for npm ci) and database support for JSON columns. Laravel Sail setup should match or exceed these requirements to guarantee compatibility. Sail typically supports recent Node.js and npm versions that satisfy these constraints.

6. Benefits of Using Sail with Twill: Leveraging Laravel Sail with Twill offers consistent and isolated development environments, ensuring that everyone on a team uses identical configurations. It also reduces "it works on my machine" problems by containerizing dependencies and services. Since Twill's asset building process uses npm scripts within the same environment, this reduces mismatches between local node/npm versions.

In terms of practical workflow, after you have installed Laravel Sail and Twill, you initiate the Sail environment by `./vendor/bin/sail up`. Then, to run the Vue dev server from Twill within Sail, use `./vendor/bin/sail npm run dev`. This command runs the Vue development hot reload server inside the containerized environment, ensuring everything is correctly linked to your Docker volumes.

When you want to build production-ready frontend assets for Twill, you use `./vendor/bin/sail npm run build`. This compiles your Vue components into static assets ready for deployment. Linting your Vue code with `./vendor/bin/sail npm run lint` ensures quality checks are done in the same environment.

The workflow is similar to any Laravel Sail project but adjusted to use Twill's frontend asset management commands. This setup guarantees your Laravel backend, frontend assets, and dev tooling stay synchronized within the Dockerized environment.

Twill and Laravel Sail are intended to work harmoniously as Twill is built on Laravel, and Sail is Laravel's official Dockerized development environment solution. The official Twill documentation mentions Sail as a recommended development environment to fulfill Twill's server and tooling requirements. Twill's use of Vue CLI is fully compatible with running the Vue build and development process inside Sail, which manages a suitable Node.js and npm environment within Docker containers.

Overview of Laravel Sail

Laravel Sail is a Docker-based development environment provided officially by Laravel. It includes PHP, MySQL/MariaDB, Redis, and Node.js, all orchestrated by Docker Compose. Sail offers a CLI (`sail`) acting as a lightweight interface to `docker-compose` commands. It provides an isolated and consistent environment for Laravel development across platforms like macOS, Linux, and Windows (via WSL2).

The Sail environment includes:

- PHP with the appropriate extensions.
- Database services like MySQL or PostgreSQL.
- Node.js and npm for frontend asset building.
- Redis, MailHog, and other optional services.

Developers run commands through Sail by prefixing commands with `./vendor/bin/sail`, e.g., `./vendor/bin/sail artisan migrate` or `./vendor/bin/sail npm run dev`. This ensures commands run inside the environment defined by Docker containers.

This environment removes the need for global Node or PHP installations on the host machine and ensures everyone works with the exact same versions and configurations.

Twill's Vue CLI Asset Management

Twill uses Vue CLI to manage its administrative interface frontend. Its npm scripts are configured to use `npm ci` for consistent dependency installation. Twill offers the capability to build, develop, and lint frontend assets through commands such as:

- `npm run dev`: Runs development server with hot reload.
- `npm run build`: Builds optimized production assets.
- `npm run lint`: Runs code linting on Vue assets.

When combined with Laravel Sail, these commands are executed within the Sail container, preserving environment consistency and leveraging Docker for the full build and development cycle.

Practical Development Workflow Example

1. Start Sail development environment:


   ./vendor/bin/sail up
   

2. Install Twill in your Laravel project:


   composer require area17/twill:"^3.0"
   php artisan twill:install
   

3. Run the Vue development server via Sail:


   ./vendor/bin/sail npm run dev
   

This starts the hot reload server for the Twill Vue components inside the Docker container.

4. When changes are ready for production, build Vue assets:


   ./vendor/bin/sail npm run build
   

5. Run lint checks as needed:


   ./vendor/bin/sail npm run lint
   

6. Manage database migrations and other Laravel Artisan commands likewise through Sail:


   ./vendor/bin/sail artisan migrate
   ./vendor/bin/sail artisan serve
   

Database and Environment Requirements

Twill's backend expects support for JSON column types in the database. Laravel Sail configurations usually come with compatible MySQL versions (5.7+ recommended) or PostgreSQL, aligning with Twill's requirements. PHP versions through Sail typically satisfy Twill's requirement for PHP 8.0 or above, and npm versions inside the Sail Node container meet the npm 5.7+ requirement for features like `npm ci`.

Customization and Extensibility

Twill's architecture with Laravel Sail enables developers to customize both backend and frontend easily. Vue components can be extended or replaced, leveraging Twill's Vue CLI tooling within the Sail environment. The flexibility of Sail allows addition of services or customization of Docker containers as the project evolves.

Summary

Using Twill's Vue CLI features with Laravel Sail is straightforward and well-supported. Twill recommends Laravel Sail as a development environment due to its adherence to Laravel's server requirements and its standardization of tooling. By running npm and Artisan commands via Sail, developers ensure consistent, containerized environments for both backend and frontend development.

This integration provides a powerful, modern full-stack development workflow combining Laravel, Twill CMS, Vue.js, and Docker:

- Twill installation and setup within Laravel.
- Laravel Sail providing the Dockerized environment.
- Vue CLI commands run inside Sail for frontend asset management.
- Consistent environment for database and PHP versions.
- Full control over and customization of Vue components.

This setup enables those building with Twill to leverage Laravel Sail's simplicity and containerization benefits while managing Vue-based frontend assets in a robust and maintainable way.