Skip to content

Commit dd036c8

Browse files
authored
Merge pull request #22 from simonfyi/master
Update build-file to Webpack 4 to use .hooks instead of .plugin
2 parents 0238fcd + f173790 commit dd036c8

5 files changed

Lines changed: 6020 additions & 20 deletions

File tree

fixtures/project/webpack.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ module.exports = {
77
},
88

99
module: {
10-
loaders: [
10+
rules: [
1111
{
1212
test: /\.(txt)$/,
13-
loader: 'file?name=[name]-[git-revision-branch]-[git-revision-version].[ext]'
13+
use: 'file-loader?name=[name]-[git-revision-branch]-[git-revision-version].[ext]'
1414
}
1515
]
1616
}

lib/build-file.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ var runGitCommand = require('./helpers/run-git-command')
33
module.exports = function buildFile (compiler, gitWorkTree, command, replacePattern, asset) {
44
var data = ''
55

6-
compiler.plugin('compilation', function (compilation) {
7-
compilation.plugin('optimize-tree', function (chunks, modules, callback) {
6+
compiler.hooks.compilation.tap('compilation', (compilation) => {
7+
compilation.hooks.optimizeTree.tapAsync('optimize-tree', (chunks, modules, callback) => {
88
runGitCommand(gitWorkTree, command, function (err, res) {
99
if (err) { return callback(err) }
1010
data = res
@@ -13,12 +13,12 @@ module.exports = function buildFile (compiler, gitWorkTree, command, replacePatt
1313
})
1414
})
1515

16-
compilation.mainTemplate.plugin('asset-path', function (path) {
16+
compilation.mainTemplate.hooks.assetPath.tap('asset-path', (path) => {
1717
return path.replace(replacePattern, data)
1818
})
1919
})
2020

21-
compiler.plugin('emit', function (compilation, callback) {
21+
compiler.hooks.emit.tapAsync('emit', (compilation, callback) => {
2222
compilation.assets[asset] = {
2323
source: function () {
2424
return data

lib/index.integration.spec.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ describe('git-revision-webpack-plugin (integration)', function () {
3131
config.output.path = targetBuild
3232
config.plugins = [
3333
new GitRevisionPlugin({
34-
gitWorkTree: targetProject,
35-
branch: true
34+
branch: true,
35+
gitWorkTree: targetProject
3636
})
3737
]
3838

@@ -70,9 +70,9 @@ describe('git-revision-webpack-plugin (integration)', function () {
7070

7171
it('should support setting the public path', function () {
7272
var versionPath = path.join(targetBuild, 'main-master-v1.0.0-1-g9a15b3b.js')
73-
var mainJs = fs.readFileSync(versionPath)
7473

75-
var expectedPublicPath = '__webpack_require__.p = "http://cdn.com/assets/master/v1.0.0-1-g9a15b3b/9a15b3ba1f8c347f9db94bcfde9630ed4fdeb1b2";'
74+
var mainJs = fs.readFileSync(versionPath, 'utf8')
75+
var expectedPublicPath = 'r.p="http://cdn.com/assets/master/v1.0.0-1-g9a15b3b/9a15b3ba1f8c347f9db94bcfde9630ed4fdeb1b2"'
7676

7777
expect(mainJs.indexOf(expectedPublicPath) !== -1).to.eql(true)
7878
})
@@ -152,9 +152,9 @@ describe('git-revision-webpack-plugin with lightweightTags option', function ()
152152

153153
it('should support setting the public path', function () {
154154
var versionPath = path.join(targetBuild, 'main-master-v2.0.0-beta.js')
155-
var mainJs = fs.readFileSync(versionPath)
155+
var mainJs = fs.readFileSync(versionPath, 'utf8')
156156

157-
var expectedPublicPath = '__webpack_require__.p = "http://cdn.com/assets/master/v2.0.0-beta/9a15b3ba1f8c347f9db94bcfde9630ed4fdeb1b2";'
157+
var expectedPublicPath = 'r.p="http://cdn.com/assets/master/v2.0.0-beta/9a15b3ba1f8c347f9db94bcfde9630ed4fdeb1b2"'
158158

159159
expect(mainJs.indexOf(expectedPublicPath) !== -1).to.eql(true)
160160
})

0 commit comments

Comments
 (0)