chushihua
This commit is contained in:
+19
@@ -0,0 +1,19 @@
|
||||
const IS_TEST = !!process.env.VUE_LOADER_TEST
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
|
||||
exports.lib = file => path.resolve(__dirname, '../', file)
|
||||
|
||||
exports.dep = dep => {
|
||||
if (IS_TEST) {
|
||||
return dep
|
||||
} else if (
|
||||
fs.existsSync(path.resolve(__dirname, '../../node_modules', dep))
|
||||
) {
|
||||
// npm 2 or npm linked
|
||||
return 'vue-loader/node_modules/' + dep
|
||||
} else {
|
||||
// npm 3
|
||||
return dep
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
const cwd = process.cwd()
|
||||
const resolve = require('resolve')
|
||||
|
||||
// attempts to first require a dep using projects cwd (when vue-loader is linked)
|
||||
// then try a normal require.
|
||||
module.exports = function tryRequire (dep) {
|
||||
let fromCwd
|
||||
try {
|
||||
fromCwd = resolve.sync(dep, { basedir: cwd })
|
||||
} catch (e) {}
|
||||
if (fromCwd) {
|
||||
return require(fromCwd)
|
||||
} else {
|
||||
try {
|
||||
return require(dep)
|
||||
} catch (e) {}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user