Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

使用相对路径加载 shim #7

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const wxsToJs = require('./lib/wxs/index')
const svgToPng = require('./lib/svg/index')
const fs = require('file-system')
const path = require('path')
const posix = require('ensure-posix-path')


// 获取文件格式
Expand All @@ -33,7 +34,7 @@ function getFilePath (filepath) {
}

function jsToAliHelp (relative, code) {
let destPath = path.relative(relative, 'my.shim.js').replace('../', '')
let destPath = `./${posix(path.relative(path.dirname(relative), 'my.shim.js'))}`

// 追加polyfill
code = `var _myShim = require('${destPath}');
Expand Down
3 changes: 2 additions & 1 deletion lib/js/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ const template = require('@babel/template')
const generate = require('@babel/generator').default
const path = require('path')
const defineHelper = template.program({ placeholderPattern: false });
const posix = require('ensure-posix-path')


exports.requireReflect = function (relative) {
let destPath = path.relative(relative, 'es.reflect').replace('../', '')
let destPath = `./${posix(path.relative(path.dirname(relative), 'es.reflect'))}`

let result = defineHelper(`var Reflect = require('${destPath}');`)()

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"babel-core": "^6.26.0",
"babel-preset-es2015": "^6.24.1",
"cssdom": "^1.0.21",
"ensure-posix-path": "^1.0.2",
"file-system": "^2.2.2",
"htmldom": "^3.0.4"
}
Expand Down