-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf(cli): added compiler cache to improve compile speed
re #1967
- Loading branch information
Showing
11 changed files
with
312 additions
and
284 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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
exports = module.exports = function initParser (ins) { | ||
['wpy', 'script', 'style', 'template', 'config', 'component', 'wxs'].forEach(k => { | ||
['wpy', 'script', 'style', 'template', 'config', 'component', 'wxs', 'file'].forEach(k => { | ||
require('../plugins/parser/' + k).call(ins); | ||
}); | ||
}; |
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,68 @@ | ||
/** | ||
* Tencent is pleased to support the open source community by making WePY available. | ||
* Copyright (C) 2017 THL A29 Limited, a Tencent company. All rights reserved. | ||
* | ||
* Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at | ||
* http://opensource.org/licenses/MIT | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. | ||
*/ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const loaderUtils = require('loader-utils'); | ||
|
||
const hashUtil = require('../../util/hash'); | ||
|
||
exports = module.exports = function () { | ||
|
||
this.register('wepy-parser-file', function (node, depFileCtx) { | ||
|
||
let file = depFileCtx.file; | ||
let fileContent = fs.readFileSync(file, 'utf-8'); | ||
let fileHash = hashUtil.hash(fileContent); | ||
|
||
if (this.compiled[file] && fileHash === this.compiled[file].hash) { // 文件 hash 一致,说明文件无修改 | ||
depFileCtx = this.compiled[file]; | ||
depFileCtx.useCache = true; | ||
|
||
return Promise.resolve(depFileCtx); | ||
} else { | ||
this.compiled[file] = depFileCtx; | ||
depFileCtx.hash = fileHash; | ||
|
||
let ext = path.extname(file); | ||
this.assets.add(depFileCtx.file, { npm: depFileCtx.npm, dep: depFileCtx.dep, component: depFileCtx.component, type: depFileCtx.type }); | ||
if (ext === '.js') { | ||
if (depFileCtx.npm) { | ||
return this.applyCompiler({ type: 'script', lang: 'js', content: fileContent }, depFileCtx); | ||
} else { | ||
return this.applyCompiler({ type: 'script', lang: 'babel', content: fileContent }, depFileCtx); | ||
} | ||
} else { | ||
if (ext === this.options.wpyExt) { | ||
// TODO: why they import a wpy file. | ||
this.hookUnique('error-handler', 'script', { | ||
ctx: depFileCtx, | ||
type: 'error', | ||
message: `Can not import a wepy component, please use "usingComponents" to declear a component`, | ||
title: 'dependence' | ||
}, { | ||
sourcemap: node.compiled.map, | ||
start: dep.loc.start | ||
}); | ||
throw new Error('EXIT'); | ||
} else { | ||
this.hookUnique('error-handler', 'script', { | ||
ctx: depFileCtx, | ||
type: 'error', | ||
message: `Unrecognized import extension: ${depFileCtx.file}`, | ||
title: 'dependence' | ||
}, { | ||
sourcemap: node.compiled.map, | ||
start: dep.loc.start | ||
}); | ||
throw new Error('EXIT'); | ||
} | ||
} | ||
} | ||
}); | ||
} |
Oops, something went wrong.