-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
32 changed files
with
17,365 additions
and
9,809 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
"@babel/preset-env", | ||
{ | ||
"targets": { | ||
"node": "10.13.0" | ||
"node": "12.22.1" | ||
} | ||
} | ||
] | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
const loader = require("./index") | ||
const loader = require('./index') | ||
|
||
module.exports = loader.default | ||
module.exports.raw = loader.raw |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
'use strict' | ||
|
||
import { util } from 'webpack' | ||
import * as path from 'path' | ||
|
||
type Options = { | ||
context: string | ||
content: string | ||
} | ||
|
||
export default function interpolateName( | ||
loaderResourcePath: string, | ||
loaderResourceQuery: string, | ||
name: string, | ||
options: Options | ||
): string { | ||
const filename = name || '[hash].[ext]' | ||
|
||
const context = options.context | ||
const content = options.content | ||
|
||
let ext = 'bin' | ||
let basename = 'file' | ||
let directory = '' | ||
let folder = '' | ||
let query = '' | ||
|
||
if (loaderResourcePath) { | ||
const parsed = path.parse(loaderResourcePath) | ||
let resourcePath = loaderResourcePath | ||
|
||
if (parsed.ext) { | ||
ext = parsed.ext.substr(1) | ||
} | ||
|
||
if (parsed.dir) { | ||
basename = parsed.name | ||
resourcePath = parsed.dir + path.sep | ||
} | ||
|
||
if (typeof context !== 'undefined') { | ||
directory = path | ||
.relative(context, resourcePath + '_') | ||
.replace(/\\/g, '/') | ||
.replace(/\.\.(\/)?/g, '_$1') | ||
directory = directory.substr(0, directory.length - 1) | ||
} else { | ||
directory = resourcePath.replace(/\\/g, '/').replace(/\.\.(\/)?/g, '_$1') | ||
} | ||
|
||
if (directory.length === 1) { | ||
directory = '' | ||
} else if (directory.length > 1) { | ||
folder = path.basename(directory) | ||
} | ||
} | ||
|
||
if (loaderResourceQuery && loaderResourceQuery.length > 1) { | ||
query = loaderResourceQuery | ||
|
||
const hashIdx = query.indexOf('#') | ||
|
||
if (hashIdx >= 0) { | ||
query = query.substr(0, hashIdx) | ||
} | ||
} | ||
|
||
let url = filename | ||
|
||
if (content) { | ||
const hash = util.createHash('md4') | ||
hash.update(content) | ||
// Match hash template | ||
url = url | ||
// `hash` and `contenthash` are same in `loader-utils` context | ||
// let's keep `hash` for backward compatibility | ||
.replace(/\[(?:([^:\]]+):)?(?:hash|contenthash)(?::([a-z]+\d*))?(?::(\d+))?\]/gi, `${hash.digest('hex')}`) | ||
} | ||
|
||
url = url | ||
.replace(/\[ext\]/gi, () => ext) | ||
.replace(/\[name\]/gi, () => basename) | ||
.replace(/\[path\]/gi, () => directory) | ||
.replace(/\[folder\]/gi, () => folder) | ||
.replace(/\[query\]/gi, () => query) | ||
|
||
return url | ||
} |
Oops, something went wrong.