Skip to content

Commit

Permalink
feat: 修复watch重启两次的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
ximing committed Apr 3, 2019
1 parent 04b3339 commit 51ba6a9
Show file tree
Hide file tree
Showing 7 changed files with 3,110 additions and 1,333 deletions.
3 changes: 2 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
"no-param-reassign": 1,
"no-nested-ternary": 1,
"no-useless-escape": "off",
"no-control-regex": "off"
"no-control-regex": "off",
"no-await-in-loop": "off"
}
}
4,318 changes: 3,040 additions & 1,278 deletions package-lock.json

Large diffs are not rendered by default.

68 changes: 36 additions & 32 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,72 +31,76 @@
],
"dependencies": {
"@babel/code-frame": "^7.0.0",
"@babel/polyfill": "^7.0.0",
"@babel/runtime": "^7.3.4",
"@tarojs/cli": "^1.2.20",
"@tarojs/components": "^1.2.20",
"@tarojs/taro": "^1.2.20",
"@tarojs/taro-weapp": "^1.2.20",
"@tarojs/transformer-wx": "^1.2.20",
"@babel/polyfill": "^7.4.3",
"@babel/runtime": "^7.4.3",
"@tarojs/cli": "^1.2.22",
"@tarojs/components": "^1.2.22",
"@tarojs/taro": "^1.2.22",
"@tarojs/taro-weapp": "^1.2.22",
"@tarojs/transformer-wx": "^1.2.22",
"chalk": "^2.4.1",
"chokidar": "^2.0.4",
"commander": "^2.19.0",
"chokidar": "^2.1.5",
"commander": "^2.20.0",
"deepmerge": "^3.2.0",
"eventemitter3": "^3.1.0",
"fs-extra": "^7.0.1",
"html-minifier": "^3.5.21",
"gulp": "^4.0.0",
"gulp-plumber": "^1.2.1",
"gulp-typescript": "^5.0.1",
"html-minifier": "^4.0.0",
"htmlparser2": "^3.10.1",
"imagemin": "^6.1.0",
"imagemin-jpegtran": "^6.0.0",
"imagemin-pngquant": "^7.0.0",
"jsonlint": "^1.6.3",
"jsonminify": "^0.4.1",
"lodash": "^4.17.11",
"micromatch": "^2.3.11",
"micromatch": "^3.1.10",
"moment": "^2.18.1",
"p-queue": "^4.0.0",
"tapable": "^1.1.1",
"watchpack": "^1.6.0"
},
"devDependencies": {
"@babel/core": "^7.2.0",
"@babel/generator": "^7.3.0",
"@babel/parser": "^7.3.1",
"@babel/core": "^7.4.3",
"@babel/generator": "^7.4.0",
"@babel/parser": "^7.4.3",
"@babel/plugin-external-helpers": "^7.2.0",
"@babel/plugin-proposal-class-properties": "^7.2.1",
"@babel/plugin-proposal-decorators": "^7.2.0",
"@babel/plugin-proposal-class-properties": "^7.4.0",
"@babel/plugin-proposal-decorators": "^7.4.0",
"@babel/plugin-proposal-do-expressions": "^7.2.0",
"@babel/plugin-proposal-export-default-from": "^7.2.0",
"@babel/plugin-proposal-export-namespace-from": "^7.2.0",
"@babel/plugin-proposal-function-bind": "^7.2.0",
"@babel/plugin-proposal-function-sent": "^7.2.0",
"@babel/plugin-proposal-json-strings": "^7.2.0",
"@babel/plugin-proposal-logical-assignment-operators": "^7.2.0",
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.2.0",
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.4.3",
"@babel/plugin-proposal-numeric-separator": "^7.2.0",
"@babel/plugin-proposal-object-rest-spread": "^7.2.0",
"@babel/plugin-proposal-object-rest-spread": "^7.4.3",
"@babel/plugin-proposal-optional-chaining": "^7.2.0",
"@babel/plugin-proposal-pipeline-operator": "^7.2.0",
"@babel/plugin-proposal-throw-expressions": "^7.2.0",
"@babel/plugin-syntax-dynamic-import": "^7.2.0",
"@babel/plugin-syntax-import-meta": "^7.2.0",
"@babel/plugin-transform-runtime": "^7.2.0",
"@babel/preset-env": "^7.2.0",
"@babel/register": "^7.0.0",
"@babel/traverse": "^7.2.3",
"@babel/types": "^7.3.0",
"@babel/plugin-transform-runtime": "^7.4.3",
"@babel/preset-env": "^7.4.3",
"@babel/register": "^7.4.0",
"@babel/traverse": "^7.4.3",
"@babel/types": "^7.4.0",
"@commitlint/cli": "^7.2.1",
"@commitlint/config-conventional": "^7.1.2",
"@types/core-js": "^2.5.0",
"@types/jest": "^24.0.11",
"babel-core": "^7.0.0-bridge.0",
"babel-eslint": "^10.0.1",
"babel-jest": "^24.5.0",
"babel-jest": "^24.7.0",
"babel-plugin-lodash": "^3.3.4",
"babel-plugin-module-resolver": "^3.1.1",
"babel-plugin-transform-decorators-legacy": "^1.3.5",
"babel-plugin-transform-define": "^1.3.1",
"cssnano": "^4.1.7",
"eslint": "^5.9.0",
"eslint": "^5.16.0",
"eslint-config-airbnb": "^17.1.0",
"eslint-config-airbnb-base": "^13.1.0",
"eslint-config-prettier": "^4.1.0",
Expand All @@ -107,28 +111,28 @@
"eslint-plugin-react": "^7.12.4",
"execution-time": "^1.3.0",
"glob": "^7.1.3",
"globby": "^9.1.0",
"globby": "^9.2.0",
"husky": "^1.2.0",
"inquirer": "^6.2.0",
"jest": "^24.5.0",
"jest": "^24.7.0",
"lint-staged": "^8.1.0",
"nyc": "^13.1.0",
"opn": "^5.4.0",
"ora": "^3.2.0",
"opn": "^6.0.0",
"ora": "^3.4.0",
"path-alias": "0.0.12",
"plugin-error": "^1.0.1",
"postcss-advanced-variables": "^3.0.0",
"postcss-load-config": "^2.0.0",
"postcss-nested": "^4.1.0",
"postcss-scss": "^2.0.0",
"prettier": "^1.15.2",
"regenerator-runtime": "^0.13.1",
"regenerator-runtime": "^0.13.2",
"replace": "^1.0.0",
"schema-utils": "^1.0.0",
"standard-version": "^5.0.2",
"ts-jest": "^24.0.0",
"ts-jest": "^24.0.1",
"tsconfig": "^7.0.0",
"tslint": "^5.12.1",
"tslint": "^5.15.0",
"tslint-config-airbnb-base": "^0.3.0",
"tslint-config-prettier": "^1.18.0",
"typescript": "^3.2.2",
Expand Down
8 changes: 7 additions & 1 deletion src/asset.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,22 @@ module.exports = class Asset {
return this.mtime !== asset.mtime;
}

render(targetPath) {
render(targetPath, mpb) {
if (targetPath || this.outputFilePath) {
if (this.__content != null) {
if (mpb.hasInit && mpb.isWatch) {
console.log('[watch]:输出文件', this.outputFilePath);
}
// TODO 做一个
// if (this.outputFilePath.includes('/mnt/d/project/mall-wxapp/dist')) {
// return fse.outputFile(targetPath || this.outputFilePath, this.contents);
// }
// return Promise.reject(new Error('dist not in project: ' + this.outputFilePath));
return fse.outputFile(targetPath || this.outputFilePath, this.contents);
}
if (mpb.hasInit && mpb.isWatch) {
console.log('[watch]:文件内容为空,不输出', this.outputFilePath);
}
return Promise.resolve(this);
}
return Promise.reject(
Expand Down
2 changes: 1 addition & 1 deletion src/assetManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ module.exports = class AssetManager {
}

emitFile(asset) {
asset.render().catch((err) => {
asset.render(null, this.mpb).catch((err) => {
console.error(err);
});
}
Expand Down
3 changes: 2 additions & 1 deletion src/loaderManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ const map = {
'babel-loader': babelLoader,
'file-loader': fileLoader,
'replace-loader': replaceLoader,
'ts-loader': tsLoaderNext,
'ts-loader': tsLoader,
'ts-loader-next': tsLoaderNext,
'postcss-loader': postcssLoader
};

Expand Down
41 changes: 22 additions & 19 deletions src/plugin/copyImagePlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,28 @@ module.exports = class CopyImagePlugin {

apply(mpb) {
mpb.hooks.afterCompile.tapPromise('AppJSON', async () => {
await Promise.all(
Object.keys(this.options.srcFiles).map((srcFile) => {
return imagemin(
[srcFile],
path.join(
this.options.output,
path.dirname(this.options.srcFiles[srcFile])
),
{
plugins: [
imageminJpegtran(),
imageminPngquant({
quality: [0.6, 0.8]
})
]
}
);
})
);
// TODO 这里需要 看下 watch下怎么监听 images目录的更改
if (!mpb.hasInit) {
await Promise.all(
Object.keys(this.options.srcFiles).map((srcFile) => {
return imagemin(
[srcFile],
path.join(
this.options.output,
path.dirname(this.options.srcFiles[srcFile])
),
{
plugins: [
imageminJpegtran(),
imageminPngquant({
quality: [0.6, 0.8]
})
]
}
);
})
);
}
});
}
};

0 comments on commit 51ba6a9

Please sign in to comment.