Skip to content

Commit 829b022

Browse files
authored
Merge pull request #115 from django-webpack/v2.0.0-release
Update docs for v2.0.0
2 parents 75b9a2e + 340dc1a commit 829b022

File tree

5 files changed

+49
-46
lines changed

5 files changed

+49
-46
lines changed

README.md

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,23 @@
33

44
Spits out some stats about webpack compilation process to a file.
55

6-
<br>
7-
86
## Install
97

108
```bash
119
npm install --save-dev webpack-bundle-tracker
1210
```
1311

14-
<br>
15-
1612
## Compatibility
1713

1814
This project is compatible with NodeJS versions 12 and up.
1915

20-
21-
<br>
16+
## Migrating from version 1.x.y to 2.x.y
17+
Starting on version 2.0.0, when creating a new instance of `BundleTracker`, the usage of the `path` parameter has been fixed and it's now being used to generate the output path for the stats file, together with the `filename` parameter. On version 2.0.0, if the `path` parameter is ommited from the constuctor call, it will attempt to place the stats file at the `output.path` directory (if also ommited, will use `'.'` as a fallback). Also, version 2.0.0 doesn't allow sub-directories to be included on the `filename`, only allowing to include them on the `path` param. To avoid those issues, when migrating, double-check if the file placement is as expected. The usage of these parameters is documented [here](#usage) and [here](#options).
2218

2319
## Usage
2420

2521
```javascript
22+
var path = require('path');
2623
var BundleTracker = require('webpack-bundle-tracker');
2724
module.exports = {
2825
context: __dirname,
@@ -31,21 +28,21 @@ module.exports = {
3128
},
3229

3330
output: {
34-
path: require('path').resolve('./assets/bundles/'),
31+
path: path.resolve('./assets/bundles/'),
3532
filename: '[name]-[hash].js',
3633
publicPath: 'http://localhost:3000/assets/bundles/',
3734
},
3835

3936
plugins: [
4037
new BundleTracker({
41-
path: __dirname,
42-
filename: './assets/webpack-stats.json',
38+
path: path.join(__dirname, 'assets'),
39+
filename: 'webpack-stats.json',
4340
}),
4441
],
4542
};
4643
```
4744

48-
`./assets/webpack-stats.json` will look like,
45+
The `webpack-stats.json` file will look like,
4946

5047
```json
5148
{
@@ -175,13 +172,11 @@ By default, the output JSON will not be indented. To increase readability, you c
175172
option to make the output legible. By default it is off. The value that is set here will be directly
176173
passed to the `space` parameter in `JSON.stringify`. More information can be found [here](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify)
177174

178-
<br>
179-
180175
## Options
181176

182177
| Name | Type | Default | Description |
183178
| ----------------- | ----------- | -------------------------------- | ------------------------------------------------------------------------------------------------------------------------------- |
184-
| `path` | `{String}` | `'.'` | Output directory of bundle tracker JSON file. |
179+
| `path` | `{String}` | `'.'` | Output directory of bundle tracker JSON file. Will attempt to use `output.path` before falling back to the default value. |
185180
| `filename` | `{String}` | `'webpack-stats.json'` | Name of the bundle tracker JSON file. |
186181
| `publicPath` | `{String}` | (ignored) | Override `output.publicPath` from Webpack config. |
187182
| `relativePath` | `{Boolean}` | `false` | Show relative path instead of absolute path for bundles in JSON Tracker file. Path are relative from path of JSON Tracker file. |

lib/index.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,14 @@ class BundleTrackerPlugin {
8484
integrityHashes: ['sha256', 'sha384', 'sha512'],
8585
});
8686

87+
if (this.options.filename?.includes('/')) {
88+
throw Error(
89+
"The `filename` shouldn't include a `/`. Please use the `path` parameter to " +
90+
"build the directory path and use `filename` only for the file's name itself.\n" +
91+
'TIP: you can use `path.join` to build the directory path in your config file.',
92+
);
93+
}
94+
8795
// Set output directories
8896
this.outputChunkDir = path.resolve(get(compiler.options, 'output.path', process.cwd()));
8997
// @ts-ignore: TS2345 this.options.path can't be undefined here because we set a default value above

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "webpack-bundle-tracker",
3-
"version": "1.8.1",
3+
"version": "2.0.0",
44
"description": "Spits out some stats about webpack compilation process to a file",
55
"keywords": [
66
"bundle",

tests/base.test.js

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ describe('BundleTrackerPlugin bases tests', () => {
4040
plugins: [
4141
new BundleTrackerPlugin({
4242
path: OUTPUT_DIR,
43-
filename: path.join(OUTPUT_DIR, 'webpack-stats.json'),
43+
filename: 'webpack-stats.json',
4444
}),
4545
],
4646
},
@@ -82,7 +82,7 @@ describe('BundleTrackerPlugin bases tests', () => {
8282
plugins: [
8383
new BundleTrackerPlugin({
8484
path: OUTPUT_DIR,
85-
filename: path.join(OUTPUT_DIR, 'webpack-stats.json'),
85+
filename: 'webpack-stats.json',
8686
logTime: true,
8787
}),
8888
],
@@ -116,7 +116,7 @@ describe('BundleTrackerPlugin bases tests', () => {
116116
plugins: [
117117
new BundleTrackerPlugin({
118118
path: OUTPUT_DIR,
119-
filename: path.join(OUTPUT_DIR, 'webpack-stats.json'),
119+
filename: 'webpack-stats.json',
120120
publicPath: 'https://test.org/statics/',
121121
}),
122122
],
@@ -161,7 +161,7 @@ describe('BundleTrackerPlugin bases tests', () => {
161161
plugins: [
162162
new BundleTrackerPlugin({
163163
path: OUTPUT_DIR,
164-
filename: path.join(OUTPUT_DIR, filename),
164+
filename,
165165
}),
166166
],
167167
},
@@ -185,11 +185,11 @@ describe('BundleTrackerPlugin bases tests', () => {
185185
);
186186
});
187187

188-
it('It should create intermdiate directory if filename option is set with intermdiate directory', done => {
188+
it('It should create intermdiate directory if path option is set with intermdiate directory', done => {
189189
const expectErrors = null;
190190
const expectWarnings = getWebpack4WarningMessage();
191191

192-
const filename = 'data/stats.json';
192+
const filename = 'stats.json';
193193

194194
testPlugin(
195195
webpack,
@@ -203,8 +203,8 @@ describe('BundleTrackerPlugin bases tests', () => {
203203
},
204204
plugins: [
205205
new BundleTrackerPlugin({
206-
path: OUTPUT_DIR,
207-
filename: path.join(OUTPUT_DIR, filename),
206+
path: path.join(OUTPUT_DIR, 'data'),
207+
filename,
208208
}),
209209
],
210210
},
@@ -221,7 +221,7 @@ describe('BundleTrackerPlugin bases tests', () => {
221221
},
222222
},
223223
},
224-
filename,
224+
`data/${filename}`,
225225
done,
226226
expectErrors,
227227
expectWarnings,
@@ -248,7 +248,7 @@ describe('BundleTrackerPlugin bases tests', () => {
248248
new BundleTrackerPlugin({
249249
path: OUTPUT_DIR,
250250
publicPath: 'https://test.org/statics/',
251-
filename: path.join(OUTPUT_DIR, 'webpack-stats.json'),
251+
filename: 'webpack-stats.json',
252252
}),
253253
],
254254
},
@@ -284,7 +284,7 @@ describe('BundleTrackerPlugin bases tests', () => {
284284
new BundleTrackerPlugin({
285285
path: OUTPUT_DIR,
286286
relativePath: true,
287-
filename: path.join(OUTPUT_DIR, 'webpack-stats.json'),
287+
filename: 'webpack-stats.json',
288288
}),
289289
],
290290
},
@@ -354,7 +354,7 @@ describe('BundleTrackerPlugin bases tests', () => {
354354
path: OUTPUT_DIR,
355355
relativePath: true,
356356
includeParents: true,
357-
filename: path.join(OUTPUT_DIR, 'webpack-stats.json'),
357+
filename: 'webpack-stats.json',
358358
}),
359359
],
360360
},
@@ -440,7 +440,7 @@ describe('BundleTrackerPlugin bases tests', () => {
440440
relativePath: true,
441441
includeParents: true,
442442
integrity: true,
443-
filename: path.join(OUTPUT_DIR, 'webpack-stats.json'),
443+
filename: 'webpack-stats.json',
444444
}),
445445
],
446446
},
@@ -554,7 +554,7 @@ describe('BundleTrackerPlugin bases tests', () => {
554554
path: OUTPUT_DIR,
555555
relativePath: true,
556556
includeParents: true,
557-
filename: path.join(OUTPUT_DIR, 'webpack-stats.json'),
557+
filename: 'webpack-stats.json',
558558
}),
559559
],
560560
},
@@ -684,7 +684,7 @@ describe('BundleTrackerPlugin bases tests', () => {
684684
path: OUTPUT_DIR,
685685
relativePath: true,
686686
includeParents: true,
687-
filename: path.join(OUTPUT_DIR, 'webpack-stats.json'),
687+
filename: 'webpack-stats.json',
688688
}),
689689
],
690690
},
@@ -748,7 +748,7 @@ describe('BundleTrackerPlugin bases tests', () => {
748748
path: OUTPUT_DIR,
749749
relativePath: true,
750750
includeParents: true,
751-
filename: path.join(OUTPUT_DIR, 'webpack-stats.json'),
751+
filename: 'webpack-stats.json',
752752
}),
753753
],
754754
},

tests/webpack5.test.js

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ describe('BundleTrackerPlugin bases tests', () => {
4040
plugins: [
4141
new BundleTrackerPlugin({
4242
path: OUTPUT_DIR,
43-
filename: path.join(OUTPUT_DIR, 'webpack-stats.json'),
43+
filename: 'webpack-stats.json',
4444
}),
4545
],
4646
},
@@ -82,7 +82,7 @@ describe('BundleTrackerPlugin bases tests', () => {
8282
plugins: [
8383
new BundleTrackerPlugin({
8484
path: OUTPUT_DIR,
85-
filename: path.join(OUTPUT_DIR, 'webpack-stats.json'),
85+
filename: 'webpack-stats.json',
8686
logTime: true,
8787
}),
8888
],
@@ -116,7 +116,7 @@ describe('BundleTrackerPlugin bases tests', () => {
116116
plugins: [
117117
new BundleTrackerPlugin({
118118
path: OUTPUT_DIR,
119-
filename: path.join(OUTPUT_DIR, 'webpack-stats.json'),
119+
filename: 'webpack-stats.json',
120120
publicPath: 'https://test.org/statics/',
121121
}),
122122
],
@@ -161,7 +161,7 @@ describe('BundleTrackerPlugin bases tests', () => {
161161
plugins: [
162162
new BundleTrackerPlugin({
163163
path: OUTPUT_DIR,
164-
filename: path.join(OUTPUT_DIR, filename),
164+
filename,
165165
}),
166166
],
167167
},
@@ -185,11 +185,11 @@ describe('BundleTrackerPlugin bases tests', () => {
185185
);
186186
});
187187

188-
it('It should create intermdiate directory if filename option is set with intermdiate directory', done => {
188+
it('It should create intermdiate directory if path option is set with intermdiate directory', done => {
189189
const expectErrors = null;
190190
const expectWarnings = getWebpack5WarningMessage();
191191

192-
const filename = 'data/stats.json';
192+
const filename = 'stats.json';
193193

194194
testPlugin(
195195
webpack5,
@@ -203,8 +203,8 @@ describe('BundleTrackerPlugin bases tests', () => {
203203
},
204204
plugins: [
205205
new BundleTrackerPlugin({
206-
path: OUTPUT_DIR,
207-
filename: path.join(OUTPUT_DIR, filename),
206+
path: path.join(OUTPUT_DIR, 'data'),
207+
filename,
208208
}),
209209
],
210210
},
@@ -221,7 +221,7 @@ describe('BundleTrackerPlugin bases tests', () => {
221221
},
222222
},
223223
},
224-
filename,
224+
`data/${filename}`,
225225
done,
226226
expectErrors,
227227
expectWarnings,
@@ -248,7 +248,7 @@ describe('BundleTrackerPlugin bases tests', () => {
248248
new BundleTrackerPlugin({
249249
path: OUTPUT_DIR,
250250
publicPath: 'https://test.org/statics/',
251-
filename: path.join(OUTPUT_DIR, 'webpack-stats.json'),
251+
filename: 'webpack-stats.json',
252252
}),
253253
],
254254
},
@@ -284,7 +284,7 @@ describe('BundleTrackerPlugin bases tests', () => {
284284
new BundleTrackerPlugin({
285285
path: OUTPUT_DIR,
286286
relativePath: true,
287-
filename: path.join(OUTPUT_DIR, 'webpack-stats.json'),
287+
filename: 'webpack-stats.json',
288288
}),
289289
],
290290
},
@@ -354,7 +354,7 @@ describe('BundleTrackerPlugin bases tests', () => {
354354
path: OUTPUT_DIR,
355355
relativePath: true,
356356
includeParents: true,
357-
filename: path.join(OUTPUT_DIR, 'webpack-stats.json'),
357+
filename: 'webpack-stats.json',
358358
}),
359359
],
360360
},
@@ -440,7 +440,7 @@ describe('BundleTrackerPlugin bases tests', () => {
440440
relativePath: true,
441441
includeParents: true,
442442
integrity: true,
443-
filename: path.join(OUTPUT_DIR, 'webpack-stats.json'),
443+
filename: 'webpack-stats.json',
444444
}),
445445
],
446446
},
@@ -554,7 +554,7 @@ describe('BundleTrackerPlugin bases tests', () => {
554554
path: OUTPUT_DIR,
555555
relativePath: true,
556556
includeParents: true,
557-
filename: path.join(OUTPUT_DIR, 'webpack-stats.json'),
557+
filename: 'webpack-stats.json',
558558
}),
559559
],
560560
},
@@ -684,7 +684,7 @@ describe('BundleTrackerPlugin bases tests', () => {
684684
path: OUTPUT_DIR,
685685
relativePath: true,
686686
includeParents: true,
687-
filename: path.join(OUTPUT_DIR, 'webpack-stats.json'),
687+
filename: 'webpack-stats.json',
688688
}),
689689
],
690690
},
@@ -748,7 +748,7 @@ describe('BundleTrackerPlugin bases tests', () => {
748748
path: OUTPUT_DIR,
749749
relativePath: true,
750750
includeParents: true,
751-
filename: path.join(OUTPUT_DIR, 'webpack-stats.json'),
751+
filename: 'webpack-stats.json',
752752
}),
753753
],
754754
},

0 commit comments

Comments
 (0)