Skip to content
This repository has been archived by the owner on Mar 8, 2020. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
Add async hook webappWebpackPluginBeforeEmit (#113)
  • Loading branch information
brunocodutra committed Jul 1, 2018
1 parent efea9ed commit 3a9d1da
Show file tree
Hide file tree
Showing 27 changed files with 180 additions and 246 deletions.
29 changes: 28 additions & 1 deletion README.md
Expand Up @@ -118,7 +118,6 @@ plugins: [
prefix: 'assets/',
// Inject html links/metadata (requires html-webpack-plugin)
inject: true,

// Favicons configuration options (see below)
favicons: {
...
Expand Down Expand Up @@ -164,6 +163,34 @@ plugins: [
]
```

## Hooks

To allow other plugins to intercept and customise assets before they are emitted, the following hooks may be tapped

### webappWebpackPluginBeforeEmit

> AsyncSeriesWaterfallHook
Example implementation:

````js
new class {
apply(compiler) {
compiler.hooks.make.tapAsync("A", (compilation, callback) => {
compilation.hooks.webappWebpackPluginBeforeEmit.tapAsync("B", (result, callback) => {
// The result of favicons library can be modified here
// and it will be returned to WebApp Plugin to be emitted.
// Add your custom functions below
console.log(result);
// Return the custom result
return callback(null, result);
});
return callback();
})
}
}
```
## Contribution
You're very welcome to contribute to this project by opening
Expand Down
3 changes: 1 addition & 2 deletions example/README.MD
Expand Up @@ -4,6 +4,5 @@

```bash
npx webpack --mode development --config ./example/basic/webpack.config.js
npx webpack --mode development --config ./example/custom/webpack.config.js
npx webpack-dev-server --mode development --config ./example/dev-server/webpack.config.js
npx webpack --mode development --config ./example/advanced/webpack.config.js
```
File renamed without changes.
11 changes: 11 additions & 0 deletions example/advanced/src/index.html
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>WebApp</title>
</head>
<body>
</body>
</html>
3 changes: 3 additions & 0 deletions example/advanced/src/logo.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
54 changes: 54 additions & 0 deletions example/advanced/webpack.config.js
@@ -0,0 +1,54 @@
const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const WebappWebpackPlugin = require('../../src/');

module.exports = (env, args) => {
return {
context: __dirname,
entry: './src/app.js',
output: {
path: path.resolve(__dirname, 'public'),
publicPath: '/myapp/',
},
plugins: [
new HtmlWebpackPlugin({
template: './src/index.html',
}),

new WebappWebpackPlugin({
logo: './src/logo.svg',
prefix: 'path/to/assets/',

// Favicons configuration
// For the complete list of options, see https://github.com/evilebottnawi/favicons#usage
favicons: {
appName: 'My WebApp',
appShortName: 'WebApp',
appDescription: 'My awesome WebApp',
developerName: 'Me',
developerURL: "https://github.com/me/",
version: "1.0.0",
},
}),

new class {
apply(compiler) {
compiler.hooks.make.tapAsync("CustomPlugin", (compilation, callback) => {
compilation.hooks.webappWebpackPluginBeforeEmit.tapAsync("CustomPlugin", (result, callback) => {
console.log(result.assets.map(({name}) => name));
console.log()
console.log("### Add custom logic to modify assets here ###");
console.log()
return callback(null, result);
});

return callback();
})
}
}
],

stats: "errors-only"
};
}
10 changes: 0 additions & 10 deletions example/basic/package.json

This file was deleted.

Binary file removed example/basic/src/favicon.png
Binary file not shown.
1 change: 0 additions & 1 deletion example/basic/src/favicon.svg

This file was deleted.

21 changes: 9 additions & 12 deletions example/basic/src/index.html
@@ -1,14 +1,11 @@
<!DOCTYPE html>
<html lang="es-MX">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Home</title>
</head>

<body>
</body>

<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>WebApp</title>
</head>
<body>
</body>
</html>
3 changes: 3 additions & 0 deletions example/basic/src/logo.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 4 additions & 8 deletions example/basic/webpack.config.js
@@ -1,24 +1,20 @@
const { resolve } = require('path');
const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const WebappWebpackPlugin = require('../../src/');

const webpack = require('webpack');

module.exports = (env, args) => {
return {
context: __dirname,
entry: './src/app.js',
output: {
path: resolve(__dirname, 'public'),
publicPath: '/',
filename: 'app.js'
path: path.resolve(__dirname, 'public'),
},
plugins: [
new HtmlWebpackPlugin({
filename: 'index.html',
template: './src/index.html',
}),
new WebappWebpackPlugin('./src/favicon.png'),
new WebappWebpackPlugin('./src/logo.svg'),
],
stats: "errors-only"
};
Expand Down
10 changes: 0 additions & 10 deletions example/custom/package.json

This file was deleted.

Binary file removed example/custom/src/favicon.png
Binary file not shown.
1 change: 0 additions & 1 deletion example/custom/src/favicon.svg

This file was deleted.

14 changes: 0 additions & 14 deletions example/custom/src/index.html

This file was deleted.

71 changes: 0 additions & 71 deletions example/custom/webpack.config.js

This file was deleted.

10 changes: 0 additions & 10 deletions example/dev-server/package.json

This file was deleted.

Empty file removed example/dev-server/src/app.js
Empty file.
Binary file removed example/dev-server/src/favicon.png
Binary file not shown.
1 change: 0 additions & 1 deletion example/dev-server/src/favicon.svg

This file was deleted.

14 changes: 0 additions & 14 deletions example/dev-server/src/index.html

This file was deleted.

0 comments on commit 3a9d1da

Please sign in to comment.