Skip to content

Commit 1975406

Browse files
committed
Rename filename to filepath
1 parent 72bbcc2 commit 1975406

File tree

4 files changed

+24
-21
lines changed

4 files changed

+24
-21
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ This project adheres to [Semantic Versioning](http://semver.org/).
55
Latest version of this document will always be available on https://github.com/SimenB/add-asset-html-webpack-plugin/releases
66

77
## [Unreleased]
8+
### Breaking
9+
- Rename `filname` to `filepath`, which makes much more sense
10+
811
### Added
912
- A Changelog!
1013
- A first attempt to add typings

README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ NOTE: This plugin requires `html-webpack-plugin@^2.10.0`.
2121
## Basic Usage
2222
The plugin will add the given JS or CSS file to the files Webpack knows about, and put it into the
2323
list of assets `html-webpack-plugin` injects into the generated html. Add the plugin the your
24-
config, providing it a filename:
24+
config, providing it a filepath:
2525

2626
```js
2727
var HtmlWebpackPlugin = require('html-webpack-plugin')
@@ -34,7 +34,7 @@ var webpackConfig = {
3434
},
3535
plugins: [
3636
new HtmlWebpackPlugin(),
37-
new AddAssetHtmlPlugin({ filename: require.resolve('./some-file') })
37+
new AddAssetHtmlPlugin({ filepath: require.resolve('./some-file') })
3838
]
3939
}
4040
```
@@ -59,19 +59,19 @@ multiple objects as an array.
5959

6060
```js
6161
new AddAssetHtmlPlugin([
62-
{ filename: require.resolve('./some-file') },
63-
{ filename: require.resolve('./some-other-file') }
62+
{ filepath: require.resolve('./some-file') },
63+
{ filepath: require.resolve('./some-other-file') }
6464
])
6565
```
6666

6767
## Options
6868
Options are passed to the plugin during instantiation.
6969

7070
```js
71-
new AddAssetHtmlPlugin({ filename: require.resolve('./some-file') })
71+
new AddAssetHtmlPlugin({ filepath: require.resolve('./some-file') })
7272
```
7373

74-
#### `filename`
74+
#### `filepath`
7575
Type: `string`, mandatory
7676

7777
The absolute path of the file you want to add to the compilation, and resulting HTML file.
@@ -84,7 +84,7 @@ If `true`, will append a unique hash of the file to the filename. This is useful
8484
#### `includeSourcemap`
8585
Type: `boolean`, default: `true`
8686

87-
If `true`, will add `filename + '.map'` to the compilation as well.
87+
If `true`, will add `filepath + '.map'` to the compilation as well.
8888

8989
#### `publicPath`
9090
Type: `string`
@@ -117,7 +117,7 @@ var webpackConfig = {
117117
devtool: '#source-map',
118118
output: {
119119
path: path.join(__dirname, 'build'),
120-
filename: '[name].dll.js',
120+
filepath: '[name].dll.js',
121121
library: '[name]_[hash]'
122122
},
123123
plugins: [
@@ -139,7 +139,7 @@ var webpackConfig = {
139139
entry: 'index.js',
140140
output: {
141141
path: 'dist',
142-
filename: 'index_bundle.js'
142+
filepath: 'index_bundle.js'
143143
},
144144
plugins: [
145145
new webpack.DllReferencePlugin({
@@ -148,7 +148,7 @@ var webpackConfig = {
148148
}),
149149
new HtmlWebpackPlugin(),
150150
new AddAssetHtmlPlugin({
151-
filename: require.resolve('./build/vendor.dll.js'),
151+
filepath: require.resolve('./build/vendor.dll.js'),
152152
includeSourcemap: true
153153
})
154154
]

addAssetHtmlPlugin.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ function resolvePublicPath(compilation, filename, publicPath) {
2020
return resolvedPublicPath;
2121
}
2222

23-
function addFileToAssets(compilation, htmlPluginData, { filename, typeOfAsset = 'js', includeSourcemap = true, hash = false, publicPath }) {
24-
if (!filename) {
23+
function addFileToAssets(compilation, htmlPluginData, { filepath, typeOfAsset = 'js', includeSourcemap = true, hash = false, publicPath }) {
24+
if (!filepath) {
2525
const error = new Error('No filename defined');
2626
compilation.errors.push(error);
2727
return Promise.reject(error);
2828
}
2929

30-
return htmlPluginData.plugin.addFileToAssets(filename, compilation)
30+
return htmlPluginData.plugin.addFileToAssets(filepath, compilation)
3131
.then(addedFilename => {
3232
let suffix = '';
3333
if (hash) {
@@ -46,7 +46,7 @@ function addFileToAssets(compilation, htmlPluginData, { filename, typeOfAsset =
4646
})
4747
.then(() => {
4848
if (includeSourcemap) {
49-
return htmlPluginData.plugin.addFileToAssets(`${filename}.map`, compilation);
49+
return htmlPluginData.plugin.addFileToAssets(`${filepath}.map`, compilation);
5050
}
5151
return null;
5252
});

test.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ test("should add file using compilation's publicPath", async t => {
4949
const compilation = { options: { output: { publicPath: 'vendor/' } } };
5050
const pluginData = Object.assign({ assets: { js: [], css: [] } }, pluginMock);
5151

52-
await addAllAssetsToCompilation([{ filename: path.join(__dirname, 'my-file.js') }], compilation, pluginData, callback);
52+
await addAllAssetsToCompilation([{ filepath: path.join(__dirname, 'my-file.js') }], compilation, pluginData, callback);
5353

5454
t.deepEqual(pluginData.assets.css, []);
5555
t.deepEqual(pluginData.assets.js, ['vendor/my-file.js']);
@@ -63,7 +63,7 @@ test('should used passed in publicPath', async t => {
6363
const compilation = { options: { output: { publicPath: 'vendor/' } } };
6464
const pluginData = Object.assign({ assets: { js: [], css: [] } }, pluginMock);
6565

66-
await addAllAssetsToCompilation([{ filename: 'my-file.js', publicPath: 'pp' }], compilation, pluginData, callback);
66+
await addAllAssetsToCompilation([{ filepath: 'my-file.js', publicPath: 'pp' }], compilation, pluginData, callback);
6767

6868
t.deepEqual(pluginData.assets.css, []);
6969
t.deepEqual(pluginData.assets.js, ['pp/my-file.js']);
@@ -80,7 +80,7 @@ test('should add file missing "/" to public path', async t => {
8080
const compilation = { options: { output: { publicPath: 'vendor' } } };
8181
const pluginData = Object.assign({ assets: { js: [], css: [] } }, pluginMock);
8282

83-
await addAllAssetsToCompilation([{ filename: 'my-file.js' }], compilation, pluginData, callback);
83+
await addAllAssetsToCompilation([{ filepath: 'my-file.js' }], compilation, pluginData, callback);
8484

8585
t.deepEqual(pluginData.assets.css, []);
8686
t.deepEqual(pluginData.assets.js, ['vendor/my-file.js']);
@@ -96,7 +96,7 @@ test('should add sourcemap to compilation', async t => {
9696
const pluginData = { assets: { js: [], css: [] }, plugin: { addFileToAssets: addFileToAssetsStub } };
9797
addFileToAssetsStub.returns(Promise.resolve('my-file.js'));
9898

99-
await addAllAssetsToCompilation([{ filename: 'my-file.js' }], compilation, pluginData, callback);
99+
await addAllAssetsToCompilation([{ filepath: 'my-file.js' }], compilation, pluginData, callback);
100100

101101
t.deepEqual(pluginData.assets.css, []);
102102
t.deepEqual(pluginData.assets.js, ['my-file.js']);
@@ -116,7 +116,7 @@ test('should skip adding sourcemap to compilation if set to false', async t => {
116116
const pluginData = { assets: { js: [], css: [] }, plugin: { addFileToAssets: addFileToAssetsStub } };
117117
addFileToAssetsStub.returns(Promise.resolve('my-file.js'));
118118

119-
await addAllAssetsToCompilation([{ filename: 'my-file.js', includeSourcemap: false }], compilation, pluginData, callback);
119+
await addAllAssetsToCompilation([{ filepath: 'my-file.js', includeSourcemap: false }], compilation, pluginData, callback);
120120

121121
t.deepEqual(pluginData.assets.css, []);
122122
t.deepEqual(pluginData.assets.js, ['my-file.js']);
@@ -136,7 +136,7 @@ test('should include hash of file content if option is set', async t => {
136136
};
137137
const pluginData = Object.assign({ assets: { js: [], css: [] } }, pluginMock);
138138

139-
await addAllAssetsToCompilation([{ filename: 'my-file.js', hash: true }], compilation, pluginData, callback);
139+
await addAllAssetsToCompilation([{ filepath: 'my-file.js', hash: true }], compilation, pluginData, callback);
140140

141141
t.deepEqual(pluginData.assets.css, []);
142142
t.deepEqual(pluginData.assets.js, ['my-file.js?5329c141291f07ab06c6']);
@@ -153,7 +153,7 @@ test('should add to css if `typeOfAsset` is css', async t => {
153153
};
154154
const pluginData = Object.assign({ assets: { js: [], css: [] } }, pluginMock);
155155

156-
await addAllAssetsToCompilation([{ filename: 'my-file.css', typeOfAsset: 'css' }], compilation, pluginData, callback);
156+
await addAllAssetsToCompilation([{ filepath: 'my-file.css', typeOfAsset: 'css' }], compilation, pluginData, callback);
157157

158158
t.deepEqual(pluginData.assets.css, ['my-file.css']);
159159
t.deepEqual(pluginData.assets.js, []);

0 commit comments

Comments
 (0)