Skip to content
Open
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
19 changes: 12 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@ module.exports = function (options) {
if (!path) {
return ''
}

const fileReg = /@import\s["'](.*\.js)["']/gi
let fileReg;
if (options.es6import) {
fileReg = /\nimport\s["'](.*\.js)["']/gi
} else {
fileReg = /\n@import\s["'](.*\.js)["']/gi
}

if (!fs.existsSync(path)) {
throw new Error('file ' + path + ' no exist')
Expand All @@ -24,10 +28,11 @@ module.exports = function (options) {
importStack[path] = path

content = content.replace(fileReg, (match, fileName) => {
let importPath = path.replace(/[^\/]*\.js$/, fileName)

if (importPath in importStack) {
return ''
let importPath = path.replace(/[^\\^\/]*\.js$/, fileName)
if (options.importStack) {
if (importPath in importStack) {
return ''
}
}

!options.hideConsole && console.log('import "' + fileName + '" --> "' + path + '"')
Expand All @@ -52,7 +57,7 @@ module.exports = function (options) {
}

let content
try {
try {
content = importJS(file.path)
} catch(e) {
cb(new gutil.PluginError('gulp-js-import', e.message))
Expand Down