assets-webpack-plugin
Advanced tools
Comparing version 5.1.2 to 6.0.0-alpha.0
@@ -5,2 +5,4 @@ 'use strict'; | ||
var _memfs = require('memfs'); | ||
var fs = require('fs'); | ||
@@ -29,3 +31,4 @@ var path = require('path'); | ||
keepInMemory: false, | ||
integrity: false | ||
integrity: false, | ||
removeFullPathAutoPrefix: false | ||
}, options); | ||
@@ -43,3 +46,3 @@ this.writer = createQueuedWriter(createOutputWriter(this.options)); | ||
var afterEmit = function afterEmit(compilation, callback) { | ||
var emit = function emit(compilation, callback) { | ||
var options = compiler.options; | ||
@@ -56,3 +59,2 @@ var stats = compilation.getStats().toJson({ | ||
}); | ||
// publicPath with resolved [hash] placeholder | ||
@@ -68,3 +70,11 @@ var assetPath = stats.publicPath && self.options.fullPath ? stats.publicPath : ''; | ||
// } | ||
// starting with webpack 5, the public path is automatically determined when possible and the path is prefaced | ||
// with `/auto/`, the `removeAutoPrefix` option can be set to turn this off | ||
if (self.options.removeFullPathAutoPrefix) { | ||
if (assetPath.startsWith('auto')) { | ||
assetPath = assetPath.substring(4); | ||
} | ||
} | ||
var seenAssets = {}; | ||
@@ -165,4 +175,11 @@ var chunks = void 0; | ||
if (self.options.keepInMemory) { | ||
compiler.outputFileSystem = (0, _memfs.createFsFromVolume)(new _memfs.Volume()); | ||
} | ||
if (!compiler.outputFileSystem.readFile) { | ||
compiler.outputFileSystem.readFile = fs.readFile.bind(fs); | ||
} | ||
if (!compiler.outputFileSystem.join) { | ||
compiler.outputFileSystem.join = path.join.bind(path); | ||
@@ -182,5 +199,5 @@ } | ||
compiler.hooks.afterEmit.tapAsync(plugin, afterEmit); | ||
compiler.hooks.emit.tapAsync(plugin, emit); | ||
} else { | ||
compiler.plugin('after-emit', afterEmit); | ||
compiler.plugin('emit', emit); | ||
} | ||
@@ -187,0 +204,0 @@ } |
@@ -86,4 +86,8 @@ 'use strict'; | ||
options.keepInMemory ? localFs.mkdirp(options.path, mkdirpCallback) : mkdirp(options.path).then(mkdirpCallback).catch(handleMkdirpError); | ||
if (options.keepInMemory) { | ||
localFs.mkdirp(options.path, mkdirpCallback); | ||
} else { | ||
mkdirp(options.path).then(mkdirpCallback).catch(handleMkdirpError); | ||
} | ||
}; | ||
}; |
29
index.js
@@ -0,1 +1,3 @@ | ||
import { createFsFromVolume, Volume } from 'memfs' | ||
const fs = require('fs') | ||
@@ -24,3 +26,4 @@ const path = require('path') | ||
keepInMemory: false, | ||
integrity: false | ||
integrity: false, | ||
removeFullPathAutoPrefix: false | ||
}, options) | ||
@@ -42,3 +45,3 @@ this.writer = createQueuedWriter(createOutputWriter(this.options)) | ||
const afterEmit = (compilation, callback) => { | ||
const emit = (compilation, callback) => { | ||
const options = compiler.options | ||
@@ -55,5 +58,4 @@ const stats = compilation.getStats().toJson({ | ||
}) | ||
// publicPath with resolved [hash] placeholder | ||
const assetPath = (stats.publicPath && self.options.fullPath) ? stats.publicPath : '' | ||
let assetPath = (stats.publicPath && self.options.fullPath) ? stats.publicPath : '' | ||
// assetsByChunkName contains a hash with the bundle names and the produced files | ||
@@ -67,3 +69,11 @@ // e.g. { one: 'one-bundle.js', two: 'two-bundle.js' } | ||
// } | ||
// starting with webpack 5, the public path is automatically determined when possible and the path is prefaced | ||
// with `/auto/`, the `removeAutoPrefix` option can be set to turn this off | ||
if (self.options.removeFullPathAutoPrefix) { | ||
if (assetPath.startsWith('auto')) { | ||
assetPath = assetPath.substring(4) | ||
} | ||
} | ||
const seenAssets = {} | ||
@@ -164,4 +174,11 @@ let chunks | ||
if (self.options.keepInMemory) { | ||
compiler.outputFileSystem = createFsFromVolume(new Volume()) | ||
} | ||
if (!compiler.outputFileSystem.readFile) { | ||
compiler.outputFileSystem.readFile = fs.readFile.bind(fs) | ||
} | ||
if (!compiler.outputFileSystem.join) { | ||
compiler.outputFileSystem.join = path.join.bind(path) | ||
@@ -181,5 +198,5 @@ } | ||
compiler.hooks.afterEmit.tapAsync(plugin, afterEmit) | ||
compiler.hooks.emit.tapAsync(plugin, emit) | ||
} else { | ||
compiler.plugin('after-emit', afterEmit) | ||
compiler.plugin('emit', emit) | ||
} | ||
@@ -186,0 +203,0 @@ } |
{ | ||
"name": "assets-webpack-plugin", | ||
"version": "5.1.2", | ||
"version": "6.0.0-alpha.0", | ||
"description": "Emits a json file with assets paths", | ||
@@ -42,3 +42,4 @@ "main": "dist/index.js", | ||
"css-loader": "4.3.0", | ||
"mini-css-extract-plugin": "0.11.2", | ||
"memfs": "3.2.0", | ||
"mini-css-extract-plugin": "0.12.0", | ||
"mocha": "8.1.3", | ||
@@ -48,3 +49,3 @@ "rimraf": "3.0.2", | ||
"standard": "14.3.4", | ||
"style-loader": "1.2.1", | ||
"style-loader": "1.3.0", | ||
"webpack": "4.44.2" | ||
@@ -51,0 +52,0 @@ }, |
@@ -143,4 +143,18 @@ # assets-webpack-plugin | ||
`/public/path/bundle.js` vs `bundle.js vs` | ||
`/public/path/bundle.js` vs `bundle.js` | ||
#### `removeFullPathAutoPrefix` | ||
Optional. `false` by default. | ||
If `true` the full path will automatically be stripped of the `/auto/` prefix generated by webpack. | ||
```js | ||
new AssetsPlugin({removeFullPathAutoPrefix: true}) | ||
``` | ||
e.g. | ||
`/public/path/bundle.js` vs `bundle.js` | ||
#### `includeManifest` | ||
@@ -147,0 +161,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
40601
608
411
13
1
1