This repository has been archived by the owner on Apr 1, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* import bits and pieces from n-webpack * demo build works * all webpack variants now help 'in house ' * Update package.json * fixed webpack dep * decouple asset hashing from webpack
- Loading branch information
1 parent
640f5a6
commit 6e91aac
Showing
9 changed files
with
163 additions
and
72 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
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,20 @@ | ||
const path = require('path'); | ||
const fs = require('fs'); | ||
const crypto = require('crypto'); | ||
|
||
module.exports = () => { | ||
const hashes = fs.readdirSync(path.join(process.cwd(), 'public')) | ||
.filter(asset => !/(\.map|about\.json|asset-hashes\.json)$/.test(asset)) | ||
.map(name => { | ||
const file = fs.readFileSync(path.join(process.cwd(), 'public', name), 'utf8'); | ||
const hash = crypto.createHash('sha1').update(file).digest('hex'); | ||
const hashedName = `${hash.substring(0, 8)}/${name}`; | ||
return { name, hashedName }; | ||
}) | ||
.reduce((previous, current) => { | ||
previous[current.name] = current.hashedName; | ||
previous[current.name + '.map'] = current.hashedName + '.map'; | ||
return previous; | ||
}, {}); | ||
fs.writeFileSync('./public/asset-hashes.json', JSON.stringify(hashes, null, 2), { encoding: 'UTF8' }); | ||
} |
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
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
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
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,29 @@ | ||
// Slightly modified version of entry-wrap-webpack-plugin https://github.com/shakyShane/entry-wrap-webpack-plugin | ||
const ConcatSource = require('webpack/lib/ConcatSource'); | ||
|
||
function Wrap (before, after, options) { | ||
this.options = options || {}; | ||
this.before = before; | ||
this.after = after; | ||
} | ||
|
||
Wrap.prototype.apply = function (compiler) { | ||
const options = this.options; | ||
const before = this.before; | ||
const after = this.after; | ||
|
||
compiler.plugin('compilation', function (compilation) { | ||
compilation.plugin('optimize-chunk-assets', function (chunks, callback) { | ||
chunks.forEach(function (chunk) { | ||
if(!chunk.initial) return; | ||
const files = chunk.files.filter(file => options.match ? options.match.test(file) : true); | ||
files.forEach(function (file) { | ||
compilation.assets[file] = new ConcatSource(before, '\n', compilation.assets[file], '\n', after); | ||
}); | ||
}); | ||
callback(); | ||
}); | ||
}); | ||
}; | ||
|
||
module.exports = Wrap; |
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,6 @@ | ||
const ExtractCssBlockPlugin = require('extract-css-block-webpack-plugin'); | ||
|
||
module.exports = function (config) { | ||
config.plugins.push(new ExtractCssBlockPlugin()); | ||
return config; | ||
} |
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
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