Skip to content

Commit

Permalink
feat: 支持任意地址链接
Browse files Browse the repository at this point in the history
  • Loading branch information
ximing committed Jul 29, 2019
1 parent ddc13bf commit f3921c5
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 14 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mpbuild",
"version": "1.2.2",
"version": "1.2.3",
"description": "",
"main": "src/index.js",
"scripts": {
Expand Down
4 changes: 4 additions & 0 deletions src/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/
const pathAlias = require('path-alias');
const path = require('path');
const os = require('os');

module.exports = class Helper {
constructor(mpb) {
Expand All @@ -23,6 +24,9 @@ module.exports = class Helper {
const newPath = pathAlias(filePath);
if (newPath !== filePath) return newPath;
}
if(filePath.includes(os.homedir())){
return filePath;
}
if (filePath[0] === '/') {
return path.resolve(this.mpb.config.src, filePath.substr(1));
}
Expand Down
14 changes: 7 additions & 7 deletions src/loader/json-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ module.exports = function(opts) {
try {
let contents = JSON.parse(asset.contents);
if (contents.extends) {
if (typeof contents.extends === 'string') {
let filePath = '';
if (contents.extends[0] === '.') {
filePath = path.resolve(asset.dir, contents.extends);
} else {
if(typeof contents.extends === 'string'){
let filePath= '';
if(contents.extends[0]==='.'){
filePath = path.resolve(asset.dir, contents.extends);
}else{
filePath = path.join(this.src, contents.extends);
}
contents = _.merge({}, contents, require(filePath));
delete contents.extends;
delete contents['extends'];
asset.contents = JSON.stringify(contents);
} else {
}else{
console.error('[json-loader] extends 必须为字符串');
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/loader/ts-loader-next/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@ const gulp = require('gulp');
const ts = require('gulp-typescript');
const through = require('through2');
const plumber = require('gulp-plumber');
const { default: PQueue } = require('p-queue');

const {default: PQueue} = require('p-queue');
const queue = new PQueue({ concurrency: 1 });

// const tsCompileQStream = require('./gulp-typescript-compile-queue');

module.exports = function(opts = {}) {
const tsProject = ts.createProject('tsconfig.json');
return async function(asset) {
// Solution to "Error: gulp-typescript: A project cannot be used in two compilations * at the same time. Create multiple projects with createProject instead." https://gist.github.com/smac89/49f3b076cd987e0875ba9bfb3fe81ef9 not work
//Solution to "Error: gulp-typescript: A project cannot be used in two compilations * at the same time. Create multiple projects with createProject instead." https://gist.github.com/smac89/49f3b076cd987e0875ba9bfb3fe81ef9 not work
let errorCount = 0,
file;
asset.contents = await queue.add(
() =>
new Promise((res) => {
gulp.src(asset.path)
gulp
.src(asset.path)
.pipe(
plumber({
errorHandler() {
Expand Down
2 changes: 1 addition & 1 deletion src/loaderManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ module.exports = class LoaderManager {
this.rules = [];
for (let i = this.mpb.config.module.rules.length - 1; i >= 0; i--) {
const rule = this.mpb.config.module.rules[i];
const { use, test, exclude, include } = rule;
let { use, test, exclude, include } = rule;
for (let j = use.length - 1; j >= 0; j--) {
const { loader, options } = use[j];
if (!use[j].loaderInstance) {
Expand Down
4 changes: 3 additions & 1 deletion src/plugin/handleJSDep.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ module.exports = class HandleJSDep {
libOutputPath
);
if (node.arguments[0].value[0] !== '.') {
node.arguments[0].value = `./${node.arguments[0].value}`;
node.arguments[0].value = `./${
node.arguments[0].value
}`;
}
deps.push({
libPath,
Expand Down

0 comments on commit f3921c5

Please sign in to comment.