Skip to content

Commit 75ea324

Browse files
committed
Split plugin into 2 files
Fixes #20
1 parent cfb0cda commit 75ea324

File tree

6 files changed

+25
-22
lines changed

6 files changed

+25
-22
lines changed

.eslintignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
index.js
1+
lib/
22
coverage/

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
index.js
1+
lib/
22

33
node_modules/
44
.idea/

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
"version": "1.0.0",
44
"description": "Add a JS or CSS assets to a generated HTML file",
55
"files": [
6-
"index.js",
6+
"lib/",
77
"index.d.ts"
88
],
9+
"main": "lib/index.js",
910
"scripts": {
10-
"clean": "del index.js coverage/ .nyc_output/",
11-
"compile": "babel addAssetHtmlPlugin.js -o index.js",
11+
"clean": "del lib/ coverage/ .nyc_output/",
12+
"compile": "babel src/ --out-dir lib/",
1213
"cover": "nyc ava",
1314
"lint": "node-version-gte-4 && eslint . || node-version-lt-4",
1415
"prepublish": "not-in-install && npm run compile || in-install",

addAssetHtmlPlugin.js renamed to src/addAllAssetsToCompilation.js

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -68,23 +68,8 @@ function addFileToAssets(compilation, htmlPluginData,
6868
}
6969

7070
// Visible for testing
71-
export function addAllAssetsToCompilation(assets, compilation, htmlPluginData, callback) {
71+
export default function (assets, compilation, htmlPluginData, callback) {
7272
return Promise.mapSeries(assets, asset => addFileToAssets(compilation, htmlPluginData, asset))
7373
.then(() => callback(null, htmlPluginData))
7474
.catch(e => callback(e, htmlPluginData));
7575
}
76-
77-
export default class AddAssetHtmlPlugin {
78-
constructor(assets = []) {
79-
this.assets = Array.isArray(assets) ? assets.slice().reverse() : [assets];
80-
}
81-
82-
/* istanbul ignore next: this would be integration tests */
83-
apply(compiler) {
84-
compiler.plugin('compilation', compilation => {
85-
compilation.plugin('html-webpack-plugin-before-html-generation', (htmlPluginData, callback) => {
86-
addAllAssetsToCompilation(this.assets, compilation, htmlPluginData, callback);
87-
});
88-
});
89-
}
90-
}

src/index.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import addAllAssetsToCompilation from './addAllAssetsToCompilation';
2+
3+
export default class AddAssetHtmlPlugin {
4+
constructor(assets = []) {
5+
this.assets = Array.isArray(assets) ? assets.slice().reverse() : [assets];
6+
}
7+
8+
/* istanbul ignore next: this would be integration tests */
9+
apply(compiler) {
10+
compiler.plugin('compilation', compilation => {
11+
compilation.plugin('html-webpack-plugin-before-html-generation', (htmlPluginData, callback) => {
12+
addAllAssetsToCompilation(this.assets, compilation, htmlPluginData, callback);
13+
});
14+
});
15+
}
16+
}

test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import path from 'path';
44
import test from 'ava';
55
import sinon from 'sinon';
66
import Promise from 'bluebird';
7-
import AddAssetHtmlPlugin, { addAllAssetsToCompilation } from './addAssetHtmlPlugin';
7+
import AddAssetHtmlPlugin from './src/index';
8+
import addAllAssetsToCompilation from './src/addAllAssetsToCompilation';
89

910
const pluginMock = {
1011
plugin: {

0 commit comments

Comments
 (0)