Skip to content

Commit

Permalink
Merge branch 'master' into develop
Browse files Browse the repository at this point in the history
* master:
  docs: update changelog
  v2.0.2
  fix(cli): 修复 dev 模式下未更新的文件也会重新生成; close #67
  • Loading branch information
qiu8310 committed May 7, 2018
2 parents 588205e + 942d96c commit 21abf31
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
2.0.2 / 2018-05-07
==================

* cli: 修复 dev 模式下未更新的文件也会重新生成 [#67](https://github.com/qiu8310/minapp/issues/67)

2.0.1 / 2018-05-05
==================

Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
"packages": [
"packages/*"
],
"version": "2.0.1"
"version": "2.0.2"
}
2 changes: 1 addition & 1 deletion packages/minapp-cli/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@minapp/cli",
"description": "minapp 命令行工具,用于创建项目、开发项目、编译项目",
"version": "2.0.1",
"version": "2.0.2",
"bin": {
"minapp": "dist/bin/minapp.js"
},
Expand Down
16 changes: 13 additions & 3 deletions packages/minapp-cli/src/webpack/plugin/WriteFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,27 @@
import * as fs from 'fs-extra'
import * as path from 'path'
import * as webpack from 'webpack'
import {createHash} from 'crypto'

import {Env} from '../../config/env'

export class WriteFile {
private sourceMap: any = {}

constructor(public env: Env) {}
apply(compiler: webpack.Compiler) {
compiler.hooks.afterEmit.tapPromise('WriteFile', async (compilation: webpack.compilation.Compilation) => {
Object.keys(compilation.assets).forEach(key => {
let file = path.join(this.env.distDir, key)
fs.ensureDirSync(path.dirname(file))
fs.writeFileSync(file, compilation.assets[key].source())
let source = compilation.assets[key].source()

let sourceHash = createHash('sha256').update(source).digest('hex')
if (this.sourceMap[key] !== sourceHash) {
this.sourceMap[key] = sourceHash

let file = path.join(this.env.distDir, key)
fs.ensureDirSync(path.dirname(file))
fs.writeFileSync(file, source)
}
})
})
}
Expand Down

0 comments on commit 21abf31

Please sign in to comment.