Skip to content

Commit e6daf96

Browse files
committed
make js default loader check work when npm-linked
1 parent f49bfa5 commit e6daf96

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

lib/loader.js

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ var path = require('path')
22
var hash = require('hash-sum')
33
var parse = require('./parser')
44
var genId = require('./utils/gen-id')
5-
var normalize = require('./utils/normalize')
6-
var loaderUtils = require('loader-utils')
75
var querystring = require('querystring')
6+
var loaderUtils = require('loader-utils')
7+
var normalize = require('./utils/normalize')
8+
var hasLoader = require('./utils/has-loader')
89

910
// internal lib loaders
1011
var selectorPath = normalize.lib('selector')
@@ -17,15 +18,9 @@ var componentNormalizerPath = normalize.lib('component-normalizer')
1718
var styleLoaderPath = normalize.dep('vue-style-loader')
1819
var hotReloadAPIPath = normalize.dep('vue-hot-reload-api')
1920

20-
var hasBabel = false
21-
try {
22-
hasBabel = !!require('babel-loader')
23-
} catch (e) {}
24-
25-
var hasBuble = false
26-
try {
27-
hasBuble = !!require('buble-loader')
28-
} catch (e) {}
21+
// check whether default js loader exists
22+
var hasBabel = hasLoader('babel')
23+
var hasBuble = hasLoader('buble')
2924

3025
var rewriterInjectRE = /\b(css(?:-loader)?(?:\?[^!]+)?)(?:!|$)/
3126

lib/utils/has-loader.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
var fs = require('fs')
2+
var path = require('path')
3+
var cwd = process.cwd()
4+
5+
module.exports = function (loader) {
6+
loader += '-loader'
7+
var hasLoader = false
8+
try {
9+
hasLoader = !!require(loader)
10+
} catch (e) {}
11+
if (!hasLoader) {
12+
hasLoader = fs.existsSync(path.resolve(cwd, 'node_modules', loader))
13+
}
14+
return hasLoader
15+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy