Skip to content

Commit

Permalink
fix(cli): fix the wrong path when usingComponents and require in wind…
Browse files Browse the repository at this point in the history
…ows environment
  • Loading branch information
fsy0718 authored and Gcaufy committed Oct 12, 2018
1 parent a5fca83 commit 4a9d552
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
13 changes: 8 additions & 5 deletions packages/cli/core/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ const fs = require('fs-extra');
const path = require('path');
const chokidar = require('chokidar');
const ResolverFactory = require('enhanced-resolve').ResolverFactory;
const node = require("enhanced-resolve/lib/node");
const NodeJsInputFileSystem = require("enhanced-resolve/lib/NodeJsInputFileSystem");
const CachedInputFileSystem = require("enhanced-resolve/lib/CachedInputFileSystem");
const node = require('enhanced-resolve/lib/node');
const NodeJsInputFileSystem = require('enhanced-resolve/lib/NodeJsInputFileSystem');
const CachedInputFileSystem = require('enhanced-resolve/lib/CachedInputFileSystem');
const parseOptions = require('./parseOptions');
const moduleSet = require('./moduleSet');
const loader = require('./loader');
const logger = require('./util/logger');
const VENDOR_DIR = require('./util/const').VENDOR_DIR;
const Hook = require('./hook');
const tag = require('./tag');
const walk = require("acorn/dist/walk");
const walk = require('acorn/dist/walk');

const initCompiler = require('./init/compiler');
const initParser = require('./init/parser');
Expand Down Expand Up @@ -208,7 +208,7 @@ class Compile extends Hook {
if (!comps) {
return null;
}

debugger
this.hookSeq('build-components', comps);
this.hookUnique('output-components', comps);

Expand Down Expand Up @@ -348,6 +348,9 @@ class Compile extends Hook {
};

for (let k in outputMap) {
if (k === 'config') {
debugger
}
if (sfc[k] && sfc[k].outputCode) {
let filename = item.outputFile + '.' + outputMap[k];
let code = sfc[k].outputCode;
Expand Down
13 changes: 10 additions & 3 deletions packages/cli/core/plugins/build/components.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,17 @@ exports = module.exports = function () {
styles.forEach(v => {
styleCode += v.parsed.code + '\n';
});

config.parsed.output.component = true;
config.outputCode = JSON.stringify(config.parsed.output, null, 4);

const {usingComponents, ...other} = config.parsed.output
let newUsingComponents = {}
for (let i in usingComponents) {
newUsingComponents[i] = usingComponents[i].replace(/\\/g, '/')
}
let output = {
...other,
usingComponents: newUsingComponents
}
config.outputCode = JSON.stringify(output, null, 4);
this.hookSeq('script-dep-fix', script.parsed);
if (!script.empty && !comp.wxComponent) {
this.hookSeq('script-injection', script.parsed, template.parsed.rel);
Expand Down
5 changes: 3 additions & 2 deletions packages/cli/core/plugins/scriptDepFix.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ exports = module.exports = function () {
} else {
if (typeof depMod === 'object' && !depMod.npm && !depMod.component) {
// dep is not a npm package, and it's not a component
let relativePath = path.relative(path.dirname(parsed.file), depMod.file);
let relativePath = path.relative(path.dirname(parsed.file), depMod.file).replace(/\\/g, '/');
replaceMent = `require('${relativePath}')`;
} else {
if (typeof moduleId === 'number') {
Expand All @@ -24,11 +24,12 @@ exports = module.exports = function () {
} else {
relativePath = path.relative(path.dirname(parsed.file), npmfile);
}
relativePath = relativePath.replace(/\\/g, '/')
replaceMent = `require('${relativePath}')(${moduleId})`;
} else if (depMod && depMod.component) {
let relativePath = path.relative(path.dirname(parsed.file), depMod.file);
let reg = new RegExp('\\' + this.options.wpyExt + '$', 'i');
relativePath = relativePath.replace(reg, '.js');
relativePath = relativePath.replace(reg, '.js').replace(/\\/g, '/');
replaceMent = `require('${relativePath}')`;
} else if (depMod === false) {
replaceMent = '{}';
Expand Down

0 comments on commit 4a9d552

Please sign in to comment.