Skip to content

Commit

Permalink
Release v1.6.0
Browse files Browse the repository at this point in the history
- added supports resolving aliases from `webpack.resolve.plugins`, #6
- update packages
  • Loading branch information
webdiscus committed Jan 11, 2022
1 parent 5f089b1 commit 380e1d0
Show file tree
Hide file tree
Showing 37 changed files with 339 additions and 110 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
# Change log

## 1.6.0 (2022-01-12)
- added supports resolving aliases from `webpack.resolve.plugins`
if a file is by `webpack.resolve.alais` not resolved, then uses the slow enhanced resolver
- update packages

## 1.5.1 (2021-12-10)
- bugfix: fix path resolving on windows
- bugfix: fix path resolving on Windows
- some optimisations
- code refactoring

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[![npm version](https://badge.fury.io/js/@webdiscus%2Fpug-loader.svg)](https://badge.fury.io/js/@webdiscus%2Fpug-loader)
[![npm](https://img.shields.io/npm/v/@webdiscus/pug-loader?logo=npm&color=brightgreen "npm package")](https://www.npmjs.com/package/@webdiscus/pug-loader "download npm package")
[![node](https://img.shields.io/node/v/@webdiscus/pug-loader)](https://nodejs.org)
[![node](https://img.shields.io/github/package-json/dependency-version/webdiscus/pug-loader/peer/webpack)](https://webpack.js.org/)
[![node](https://img.shields.io/github/package-json/dependency-version/webdiscus/pug-loader/peer/pug)](https://github.com/pugjs/pug)
Expand All @@ -19,7 +19,7 @@ The pug loader resolves paths and webpack aliases for `extends`/`include`/`requi
- supports features and options of original [`pugjs/pug-loader`](https://github.com/pugjs/pug-loader/)
- up to 4x faster than original `pugjs/pug-loader` at webpack starting
- up to 8x faster than original `pugjs/pug-loader` at webpack watching during compile changes in dependencies
- supports Webpack `resolve.alias`, works with and without the prefixes: `~` `@`
- supports Webpack `resolve.alias` and `resolve.plugins`, works with and without the prefixes `~` `@`
- supports integration with `Angular Component`
- supports the syntax of `CommonJS` and `ES modules` in generated templates for loading them via `require` or `import`
- compiling a pug into a template function, e.g. using in javascript:
Expand Down
4 changes: 2 additions & 2 deletions examples/angular-component-html/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "ng-app",
"description": "Usage the pug template in angular component",
"version": "0.0.1",
"version": "1.0.0",
"scripts": {
"ng": "npx -p @angular/cli ng",
"start": "npx -p @angular/cli ng serve",
Expand Down Expand Up @@ -31,7 +31,7 @@
"@angular/compiler-cli": "~13.0.0",
"@types/jasmine": "~3.10.0",
"@types/node": "^12.11.1",
"@webdiscus/pug-loader": "^1.5.1",
"@webdiscus/pug-loader": "^1.6.0",
"html-loader": "^3.0.1",
"pug-plugin-ng": "^0.0.3",
"jasmine-core": "~3.10.0",
Expand Down
18 changes: 9 additions & 9 deletions examples/angular-component-html/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ module.exports = {

module: {
rules: [
/*{
test: /\.pug$/,
loader: 'pug-loader',
options: {
method: 'render',
doctype: 'html',
plugins: [require('pug-plugin-ng')],
},
},*/
// {
// test: /\.pug$/,
// loader: 'pug-loader',
// options: {
// method: 'render',
// doctype: 'html',
// plugins: [require('pug-plugin-ng')],
// },
// },

{
test: /\.pug$/,
Expand Down
4 changes: 2 additions & 2 deletions examples/angular-component-render/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "ng-app",
"description": "Usage the pug template in angular component",
"version": "0.0.1",
"version": "1.0.0",
"scripts": {
"ng": "npx -p @angular/cli ng",
"start": "npx -p @angular/cli ng serve",
Expand Down Expand Up @@ -31,7 +31,7 @@
"@angular/compiler-cli": "~13.0.0",
"@types/jasmine": "~3.10.0",
"@types/node": "^12.11.1",
"@webdiscus/pug-loader": "^1.5.1",
"@webdiscus/pug-loader": "^1.6.0",
"html-loader": "^3.0.1",
"pug-plugin-ng": "^0.0.3",
"jasmine-core": "~3.10.0",
Expand Down
15 changes: 10 additions & 5 deletions examples/webpack-app-hello-pug/README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
## Install
npm install
```
npm i
```

## Start local app in browser
## Start the app in browser for local development
```
npm run start
> !!! currently not work !!!
>
> Bugfix in progress...
```

## Build
```
npm run build
```

## Watch
```
npm run watch
```
15 changes: 8 additions & 7 deletions examples/webpack-app-hello-pug/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,20 @@
"name": "webpack-app",
"version": "1.0.0",
"description": "Simple web app",
"author": "webdiscus",
"license": "ISC",
"main": "index.js",
"scripts": {
"__start": "webpack serve",
"start": "webpack serve",
"build": "webpack --mode=production --progress",
"watch": "webpack --mode=production --watch --progress"
},
"author": "",
"license": "ISC",
"devDependencies": {
"@webdiscus/pug-loader": "^1.5.1",
"pug-plugin": "^1.1.0",
"webpack": "^5.64.0",
"@webdiscus/pug-loader": "^1.6.0",
"css-loader": "^6.5.1",
"pug-plugin": "^1.2.0",
"webpack": "^5.65.0",
"webpack-cli": "^4.9.1",
"webpack-dev-server": "^4.5.0"
"webpack-dev-server": "^4.7.2"
}
}
1 change: 0 additions & 1 deletion examples/webpack-app-hello-pug/src/app/app.pug
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ p Hello Pug!
img(src=require('Images/image.jpeg'))

- var colors = require('App/colors.json')

.colors
each color in colors
div(style=`background-color:${color.hex};`)= color.name
31 changes: 19 additions & 12 deletions examples/webpack-app-hello-pug/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ module.exports = {

plugins: [
// extract HTML from pug files defined by webpack entry
new PugPlugin(),
new PugPlugin({
// extract CSS from required styles in pug and from webpack entry
modules: [PugPlugin.extractCss()],
}),
],

module: {
Expand All @@ -61,8 +64,9 @@ module.exports = {
test: /\.(css)/,
type: 'asset/resource',
generator: {
filename: 'assets/css/[hash][ext][query]',
filename: 'assets/css/[name].[hash][ext]',
},
use: ['css-loader'],
},
],
},
Expand All @@ -71,21 +75,24 @@ module.exports = {
static: {
directory: path.join(__dirname, 'public'),
},
compress: true,
port: 9000,
https: false,
// open in default browser
open: true,
// define a development browser
/*open: {
app: {
name: 'Firefox',
},
},*/
liveReload: true,

hot: true,
client: {
progress: true,
},
compress: true,
headers: {
'Cross-Origin-Opener-Policy': 'same-origin',
'Cross-Origin-Embedder-Policy': 'require-corp',
},
// open in default browser
open: true,
// open: {
// app: {
// name: 'Firefox',
// },
// },
},
};
18 changes: 10 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@webdiscus/pug-loader",
"version": "1.5.1",
"version": "1.6.0",
"description": "The pug loader resolves paths and webpack aliases in a pug template and compiles it to HTML or into a template function.",
"keywords": [
"pug",
Expand All @@ -11,7 +11,8 @@
"render",
"html",
"template",
"pug-loader"
"pug-loader",
"pug-plugin"
],
"license": "ISC",
"author": "webdiscus (https://github.com/webdiscus)",
Expand Down Expand Up @@ -65,15 +66,16 @@
"webpack-merge": "^5.8.0"
},
"devDependencies": {
"@babel/core": "^7.16.0",
"@babel/preset-env": "^7.16.4",
"@types/jest": "^27.0.3",
"html-loader": "^3.0.1",
"jest": "^27.4.3",
"@babel/core": "^7.16.7",
"@babel/preset-env": "^7.16.8",
"@types/jest": "^27.4.0",
"html-loader": "^3.1.0",
"jest": "^27.4.7",
"jstransformer-markdown-it": "^2.1.0",
"prettier": "^2.5.1",
"pug-plugin": "^1.1.0",
"pug-plugin": "^1.2.0",
"rimraf": "^3.0.2",
"tsconfig-paths-webpack-plugin": "^3.5.2",
"webpack": "^5.65.0"
}
}
8 changes: 0 additions & 8 deletions src/asset-loader.js

This file was deleted.

60 changes: 60 additions & 0 deletions src/directory-resolve-plugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
const plugin = 'directory-resolve-plugin';

//// pipeline ////
// The list of event names.

// resolve
// internal-resolve
// new-interal-resolve
// parsed-resolve
// described-resolve
// internal
// raw-module
// module
// resolve-as-module
// undescribed-resolve-in-package
// resolve-in-package
// resolve-in-existing-directory
// relative
// described-relative
// directory
// undescribed-existing-directory
// existing-directory
// undescribed-raw-file
// raw-file
// file
// final-file
// existing-file
// resolved

// The source is start pipeline: use the prefix `before` or `after` with pipeline, e.g. `before-resolve`.
// The Target is one of pipeline list.

class DirectoryResolvePlugin {
/**
*
* @param {string} source The source is the name of the event that starts the pipeline.
* Use the prefix `before` or `after` with event name, e.g. `before-resolve`.
* @param {string} target The target is the event name what should fire.
*/
constructor(source, target) {
this.source = source;
this.target = target;
}

apply(resolver) {
const target = resolver.ensureHook(this.target);
//console.log('\n** [directory-resolve-plugin] target: ', target);

resolver.getHook(this.source).tapAsync(plugin, (request, resolveContext, callback) => {
let message = null;
//console.log('\n** [directory-resolve-plugin] request: ', request, resolveContext);
//console.log('\n** [directory-resolve-plugin]\n: ', resolveContext.stack);

// Any logic you need to create a new `request` can go here
resolver.doResolve(target, request, message, resolveContext, callback);
});
}
}

module.exports = DirectoryResolvePlugin;
Loading

0 comments on commit 380e1d0

Please sign in to comment.