Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 03f6cb5
Showing
5 changed files
with
121 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Copyright (c) 2014 Jason Anderson | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# entry-manifest-webpack-plugin | ||
|
||
Allows exporting a JSON file that maps entry resource names to their resulting asset files. Webpack can then read this mapping (assuming it is provided to webpack somehow on the client) from here instead of storing the mapping in its bootstrap, which allows to actually leverage long-term caching of the bootstrap file. | ||
|
||
## Usage | ||
|
||
Install via npm: | ||
|
||
```shell | ||
npm install entry-manifest-webpack-plugin | ||
``` | ||
|
||
And then require and provide to webpack: | ||
|
||
```javascript | ||
// in webpack.config.js or similar | ||
var EntryManifestPlugin = require('entry-manifest-webpack-plugin'); | ||
|
||
module.exports = { | ||
// your config values here | ||
plugins: [ | ||
new EntryManifestPlugin({ | ||
filename: "manifest.json", | ||
manifestVariable: "webpackManifest" | ||
}) | ||
] | ||
}; | ||
``` | ||
|
||
### Options | ||
|
||
#### `filename` | ||
|
||
Where the manifest will be exported to on bundle compilation. This will be relative to the main webpack output directory. Default = `"manifest.json"` | ||
|
||
#### `manifestVariable` | ||
|
||
What JS variable on the client webpack should refer to when requiring entry chunks. Default = `"webpackManifest"` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
var RawSource = require("webpack-core/lib/RawSource"); | ||
|
||
function ExternalChunkHashesPlugin() { | ||
} | ||
module.exports = ExternalChunkHashesPlugin; | ||
|
||
ExternalChunkHashesPlugin.prototype.constructor = ExternalChunkHashesPlugin; | ||
ExternalChunkHashesPlugin.prototype.apply = function(compiler) { | ||
compiler.plugin("this-compilation", function(compilation) { | ||
compilation.mainTemplate.plugin("require-ensure", function(_, chunk, hash) { | ||
var filename = this.outputOptions.filename; | ||
var manifestFile = this.outputOptions.manifestFile || "manifest.json"; | ||
var chunkManifest; | ||
|
||
if (filename) { | ||
chunkManifest = [chunk].reduce(function registerChunk(manifest, c) { | ||
if(c.name in manifest) return manifest; | ||
|
||
if(c.entry) { | ||
manifest[c.name] = undefined; | ||
} else { | ||
manifest[c.name] = compilation.applyPluginsWaterfall("asset-path", filename, { | ||
hash: hash, | ||
chunk: c | ||
}); | ||
} | ||
return c.chunks.reduce(registerChunk, manifest); | ||
}, {}); | ||
this.outputOptions.chunkFilename = "__ENTRY_MANIFEST__"; | ||
// mark as asset for emitting | ||
compilation.assets[manifestFile] = new RawSource(JSON.stringify(chunkManifest)); | ||
} | ||
|
||
return _; | ||
}); | ||
}); | ||
|
||
compiler.plugin("compilation", function(compilation) { | ||
compilation.mainTemplate.plugin("require-ensure", function(_, chunk, hash, chunkIdVar) { | ||
var chunkManifestVariable = this.outputOptions.jsonpManifestVariable || "webpackManifest"; | ||
return _.replace("\"__ENTRY_MANIFEST__\"", | ||
"window[\"" + chunkManifestVariable + "\"][" + chunkIdVar + "]"); | ||
}); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"name": "entry-manifest-webpack-plugin", | ||
"version": "0.0.1", | ||
"description": "Allows exporting a manifest that maps entry chunk names to their output files, instead of keeping the mapping inside the webpack bootstrap.", | ||
"main": "lib/EntryManifestPlugin.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"author": { | ||
"name": "Jason Anderson", | ||
"email": "diurnalist@gmail.com", | ||
"url": "http://diurnal.st" | ||
}, | ||
"license": "MIT", | ||
"dependencies": { | ||
"webpack-core": "^0.4.8" | ||
} | ||
} |