Skip to content
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

Add support for recursive compiling #14

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
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
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# laravel-mix-pug
# laravel-mix-pug-recursive
Laravel Mix Plugin for compiling Pug/Jade templates.

<p align="center">
Expand All @@ -9,24 +9,24 @@ Laravel Mix Plugin for compiling Pug/Jade templates.

## Introduction

This package provides a plugin for Laravel Mix to compile pug templates. `laravel-mix-pug` requires Laravel Mix to work. Please follow the instructions on how to use it on the package [repository](https://github.com/JeffreyWay/laravel-mix).
This package provides a plugin for Laravel Mix to compile pug templates. `laravel-mix-pug-recursive` requires Laravel Mix to work. Please follow the instructions on how to use it on the package [repository](https://github.com/JeffreyWay/laravel-mix).

## Usage

Install this package into your project:

```
npm install laravel-mix-pug --save-dev
npm install laravel-mix-pug-recursive --save-dev
```
Head over to your `webpack.mix.js` and register it on the Laravel Mix API:

```js
let mix = require('laravel-mix');
mix.pug = require('laravel-mix-pug');
mix.pug = require('laravel-mix-pug-recursive');

mix.js('src/app.js', 'dist')
.sass('src/app.scss', 'dist')
.pug('src/*.pug', 'dist')
.pug('src/**/*.pug', 'dist')
.setPublicPath('dist');
```

Expand All @@ -37,7 +37,7 @@ You can also pass in a third optional parameter: *options* object. It accepts tw
This is a path to a folder with seed files. Files can be of type `json` or `yaml`. They will be parsed and provided in your pug template locals under the seed file name and then contents.

```js
mix.pug('src/*.pug', 'dist', {seeds:'src/seeds'});
mix.pug('src/**/*.pug', 'dist', {seeds:'src/seeds'});
```

And if you have a file `demo.yml` in there all the content will be available in your template under
Expand All @@ -50,7 +50,7 @@ a(href=seed.demo.anchor.link) seed.demo.anchor.name
It's possible to pass in an object which will be added to locals in your pug templates:

```js
mix.pug('src/*.pug', 'dist', {
mix.pug('src/**/*.pug', 'dist', {
locals: {
config: { baseUrl: 'http://my-template.dev/' }
}
Expand All @@ -68,7 +68,7 @@ script(src=`{config.baseUrl}js/main.js`)
You can pass in [pug config options](https://pugjs.org/api/reference.html#options) under `pug` key:

```js
mix.pug('src/*.pug', 'dist', {
mix.pug('src/**/*.pug', 'dist', {
pug: {
pretty: true,
debug: true
Expand All @@ -81,7 +81,7 @@ It is possible to change to output file extension and exclude part of the path.
i.e.: You want your destination file to be in `resources/assets/views` and the folder structure in there to continue from the `resources/assets/pug/{..}`:

```js
mix.pug('resources/assets/pug/*.pug', 'resources/assets/views', {
mix.pug('resources/assets/pug/**/*.pug', 'resources/assets/views', {
ext: '.blade.php',
excludePath: 'resources/assets/pug'
});
Expand Down
15 changes: 8 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"name": "laravel-mix-pug",
"version": "0.3.0",
"name": "laravel-mix-pug-recursive",
"version": "0.3.6",
"description": "Laravel Mix Plugin for compiling Pug/Jade templates.",
"main": "src/index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/matejsvajger/laravel-mix-pug.git"
"url": "git+https://github.com/mikemartin/laravel-mix-pug-recursive.git"
},
"keywords": [
"laravel",
Expand All @@ -18,15 +18,16 @@
"author": "Matej Svajger <[email protected]>",
"license": "MIT",
"bugs": {
"url": "https://github.com/matejsvajger/laravel-mix-pug/issues"
"url": "https://github.com/mikemartin/laravel-mix-pug-recursive/issues"
},
"homepage": "https://github.com/matejsvajger/laravel-mix-pug#readme",
"homepage": "https://github.com/mikemartin/laravel-mix-pug-recursive#readme",
"dependencies": {
"foldero": "^0.1.1",
"glob": "^7.1.2",
"js-yaml": "^3.9.1"
"js-yaml": "^3.9.1",
"mkdirp": "^0.5.1"
},
"peerDependencies": {
"laravel-mix": "^1.4.2 || 2.x || 3.x || 4.x"
"laravel-mix": "^1.4.2 || 2.x || 3.x || 4.x || 5.x || 6.x"
}
}
7 changes: 4 additions & 3 deletions src/MixPugTask.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const glob = require('glob');
const path = require('path');
const pug = require('pug');
const fs = require('fs');
const mkdirp = require('mkdirp');

class MixPugTask extends Task {

Expand Down Expand Up @@ -164,10 +165,10 @@ class MixPugTask extends Task {
prepareAssets(src) {
let file = new File(src);
let pathFromBase = this.relativePathFromSource(file.base(), this.excludePath);
let baseDir = path.join(pathFromBase, this.dest);

let baseDir = (new File(path.join(this.dest, pathFromBase))).absolutePath;
if (!File.exists(baseDir)) {
new File(baseDir).makeDirectories();
mkdirp.sync(baseDir);
}

let output = path.join(baseDir, file.nameWithoutExtension() + this.extension);
Expand Down
5 changes: 3 additions & 2 deletions src/PugSeeder.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const _ = require('lodash');
const glob = require('glob');
const yaml = require('js-yaml');
const foldero = require('foldero');
const { extname } = require('path');

class PugSeeder {

Expand Down Expand Up @@ -41,7 +42,7 @@ class PugSeeder {
let json = {};

try {
json = (path.extname(file).match(/^.ya?ml$/)) ?
json = (extname(file).match(/^.ya?ml$/)) ?
yaml.safeLoad(fs.readFileSync(file, 'utf8')):
JSON.parse(fs.readFileSync(file, 'utf8'));
} catch(e) {
Expand Down Expand Up @@ -73,4 +74,4 @@ class PugSeeder {

}

module.exports = PugSeeder;
module.exports = PugSeeder;
11 changes: 6 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
let Verify, Assert;
let Verify, Dependencies;
// [email protected]
try { Verify = require('laravel-mix/src/Verify'); }
// laravel-mix@>=2.x
catch (e) { Assert = require('laravel-mix/src/Assert'); }
catch (e) { Dependencies = require('laravel-mix/src/Dependencies'); }

const notifier = require('node-notifier');
const glob = require('glob');

function pug(src, dest, options) {
function pug(src, dest, options = {}) {

// [email protected]
if (Verify != null) Verify.dependency('pug', ['pug'], true);
// laravel-mix@>=2.x
else Assert.dependencies(['pug'], true);
else new Dependencies(['pug']).install(true);

let files = glob.sync(src);
let globOption = options.glob ? options.glob : {}
let files = glob.sync(src, globOption);

let MixPugTask = require('./MixPugTask');

Expand Down