Skip to content

Commit

Permalink
Added GitHub Pages for documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
visto9259 committed Oct 7, 2023
1 parent 0536da2 commit 005b23e
Show file tree
Hide file tree
Showing 36 changed files with 9,310 additions and 0 deletions.
20 changes: 20 additions & 0 deletions docs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Dependencies
/node_modules

# Production
/build

# Generated files
.docusaurus
.cache-loader

# Misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*
41 changes: 41 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Website

This website is built using [Docusaurus 2](https://docusaurus.io/), a modern static website generator.

### Installation

```
$ yarn
```

### Local Development

```
$ yarn start
```

This command starts a local development server and opens up a browser window. Most changes are reflected live without having to restart the server.

### Build

```
$ yarn build
```

This command generates static content into the `build` directory and can be served using any static contents hosting service.

### Deployment

Using SSH:

```
$ USE_SSH=true yarn deploy
```

Not using SSH:

```
$ GIT_USER=<Your GitHub username> yarn deploy
```

If you are using GitHub pages for hosting, this command is a convenient way to build the website and push to the `gh-pages` branch.
3 changes: 3 additions & 0 deletions docs/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
presets: [require.resolve('@docusaurus/core/lib/babel/preset')],
};
11 changes: 11 additions & 0 deletions docs/blog/2020-04-10-zf3-webpack.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
title: Zend Framework and Webpack integration
authors: ericr
---
If you are using ZF3 MVC and want to also use Webpack to bundle and manage
dependencies in your frontend Javascript, I wrote a [guide](/docs/zend-webpack-guide-getting-started) that
explains how to use the [`zend-webpack`](https://github.com/visto9259/zend-webpack) ZF3 module and [`php-webpack-plugin`](https://github.com/visto9259/php-webpack-plugin)
Webpack plugin to integrate and automate the bundling of frontend JS scripts in a ZF3 Mvc application.

I hope you find it useful.

11 changes: 11 additions & 0 deletions docs/blog/2020-07-10-laminas-webpack.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
title: Laminas Framework and Webpack integration
authors: ericr
---
If you are using Laminas MVC and want to also use Webpack to bundle and manage
dependencies in your frontend Javascript, I wrote a [guide](/docs/zend-webpack-guide-getting-started) that
explains how to use the [`zend-webpack`](https://github.com/visto9259/zend-webpack) Laminas module and [`php-webpack-plugin`](https://github.com/visto9259/php-webpack-plugin)
Webpack plugin to integrate and automate the bundling of frontend JS scripts in a Laminas Mvc application.

This is a replacement for `zend-webpack` which is now abandoned.

7 changes: 7 additions & 0 deletions docs/blog/2020-07-10-zend-webpack-abandoned.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
title: zend-webpack is abandoned
authors: ericr
---
`zend-webpack` is now abandoned and is no longer supported.

Please use `laminas-webpack` instead.
21 changes: 21 additions & 0 deletions docs/blog/2022-08-02-laminas-webpack-2-0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
title: laminas-webpack 2.0 released.
authors: ericr
---
Version 2.0 of `laminas-webpack` is now available.

## Summary
This release does not add new functionality.

- PHP versions supported: 7.4, 8.0. 8.1
- Added type declarations
- Added test and code checking

## Breaking Changes:
- Removed deprecated functions from version 1:
- `WebpackOptions::getScriptList($routeMatched)`
- Minimum requirements for PHP is 7.4.

## Credits
Thanks to [fabiang](https://github.com/fabiang) who made the updates.

4 changes: 4 additions & 0 deletions docs/blog/authors.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ericr:
name: Eric Richer
url: https://github.com/visto9259
image_url: https://github.com/visto9259.png
8 changes: 8 additions & 0 deletions docs/docs/getting-started/_category_.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"label": "Getting Started",
"position": 2,
"link": {
"type": "generated-index",
"description": "Getting started with laminas-webpack"
}
}
20 changes: 20 additions & 0 deletions docs/docs/getting-started/installation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
sidebar_position: 1
label: Installation
---
# Installation

## Requirements

Using Composer:

$ composer require visto9259/laminas-webpack

Or, alternatively, manually add the following to your `composer.json`, in the `require` section:
````json
{
"require": {
"visto9259/laminas-webpack" : "^1.0"
}
}
````
44 changes: 44 additions & 0 deletions docs/docs/guides/1-getting-started.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
id: laminas-webpack-guide-getting-started
position: 1
title: Getting started
sidebar_label: Getting started
---
In a typical Laminas MVC application, HTML pages are rendered using views.

It is also typical to enhance the rendered html using Javascript. A typical case would be to
use packages like [Bootstrap](https://getbootstrap.com) and [Jquery](https://jquery.com/).

In a typical Laminas View template, you would include the following to add script loading tags
to your head section.

````php
<?php
$this->headscript()->appendFile("https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js");
$this->headscript()->appendFile("https://code.jquery.com/jquery-3.4.1.slim.min.js");
$this->headscript()->appendFile("https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js");
````

When your application starts to have multiple pages and when you want to have different
JS scripts for each page, it came become difficult to keep track of which JS packages need to
be loaded for a given page.

* What scripts should be rendered by the layout template?
* What scripts should be rendered by a page view template?
* Where do you render you own scripts for a give page?

If you are using a frontend framework like Angular or React, you know that the number of
individual JS files can increase tremendously. Most probably, you are also using Webpack and transpiler
like Babel to compile and manage dependencies.

I have use RequireJS in the past to manage the dependencies between scripts
and packages when my scripts were somewhat simple. Now that I am moving to React, I find that
the number of scripts is increasing. In order to automate everyting, I also started using Webpack.








169 changes: 169 additions & 0 deletions docs/docs/guides/2-setting-up.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
---
id: laminas-webpack-guide-setting-up
title: Setting up Laminas MVC to use Webpack
sidebar_label: Setting up Laminas MVC to use Webpack
---
>This is not a guide on setting up a Webpack environment. I got inspired by this excellent [answer](https://stackoverflow.com/questions/43436754/using-webpack-with-an-existing-php-and-js-project)
on Stackoverflow by [Loilo](https://github.com/Loilo). Further investigations led me to the
Webpack plugin [castiron/webpack-php-manifest](https://github.com/castiron/webpack-php-manifest).

>This is not a guide on setting up a Laminas MVC application either. The Laminas MVC Skeleton is a good place to start
and this is what I used for my own application.

## Setting up your Laminas application

So here's a typical Laminas MVC directory structure:

````
.
+--config
| +--autoload
| application.config.php
+--data
+--module
| +--Application
| | +--config
| | +--src
| | +--view
| +--AnotherModule
+--public
| +--js
| +--css
+--vendor
composer.json
composer.lock
````

So where's the best place to hold all your JS sources? That's up to you. I personally
decided to have all my JS sources in a `browser` subfolder of the root directory.

Then I followed the guidelines provided by [Loilo](https://github.com/Loilo) in his Stackoverflow [answer](https://stackoverflow.com/questions/43436754/using-webpack-with-an-existing-php-and-js-project)
and created `src` and `build` folders under `browser` like this:

````
.
+--browser
| +--build
| +--src
+--config
| +--autoload
| application.config.php
+--data
+--module
| +--Application
| | +--config
| | +--src
| | +--view
| +--AnotherModule
+--public
| +--js
| +--css
+--vendor
composer.json
composer.lock
````

I also decided that the root folder would also be where the `node` modules would be located.
It could have been anywhere but it allows you to use all kinds of `node` tools and automation
in the project. So once you initialize your `node` environment, you end up with this:

````
.
+--browser
| +--build
| +--src
+--config
| +--autoload
| application.config.php
+--data
+--module
| +--Application
| | +--config
| | +--src
| | +--view
| +--AnotherModule
+--node_modules
+--public
| +--js
| +--css
+--vendor
composer.json
composer.lock
package.json
````

## Setting up your JS files

How you want to set up your JS source files is up to you.

I personally wanted to have some level of structure and organization in source files that
matches the structure of my application's pages. Since each page rendered by the application
is its own frontend JS app, my `src` folder matches the `module/controller-action/view` structure.

In addition, you can share common JS modules using a `lib` folder within the `src` folder.

For example, if you have a module called `mymodule` with a controller called `mycontroller`
and the following actions `index`, `edit`, `detail` with corresponding view templates, then you
can use a structure like this:

````
.
+--browser
| +--build
| +--src
| +--lib
| | common-code.js
| +--mymodule
| +--mycontroller
| index.js
| details.js
| edit.js
+--...
````
The important concept here is that `index.js`, `details.js` and `edit.js` are _entry points_
for the JS scripts that the corresponding view template will need to load.

This means that `index.js` will
need to _require_ or _import_ all the libraries and modules that it needs to rendered the frontend
part of the page such that Webpack can create a bundle of scripts for the view.

As example, if you need Bootstrap in your page, then `index.js` could look like:

````javascript
/**
* This imports Bootstrap JS and its css
*/
import 'bootstrap';
import 'bootstrap/dist/css/bootstrap.min.css';

/*
you own code go here
*/
````
Webpack will include Bootstrap's dependencies `Jquery` and `popper.js` in the bundle.

## Sharing entry points

Obviously, if you follow strictly my proposed structure, you would end up with as many JS files
as you have pages in your application.

To avoid this, I usually have a _common_ entry point for all pages that use the same bundle like
the `Bootstrap` bundle above. This is useful when the only thing your page needs is `Bootstrap`.

## Using the bundles in Laminas MVC

Laminas Skeleton application expects the `public` folder to hold all _Internet-facing_ assets.
Therefore, all the bundles generated by Webpack from the `src` files should go somewhere under the `public` folder.
I personally use a `public/dist` folder to hold the generated bundles.


Depending on how you set up Webpack, there will be many bundles generated in your `public/dist` folder. You will need
to make sure that your Laminas view template loads all the scripts of an entry point's bundle which
can very quickly become complex unless you automate the development process.

More on this in the [next page](3-setting-webpack.md) of this guide.





Loading

0 comments on commit 005b23e

Please sign in to comment.