Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

gulp-path-alias

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gulp-path-alias - npm Package Compare versions

Comparing version
1.0.1
to
1.0.2
+7
-5
index.js

@@ -12,6 +12,7 @@ const path = require('path');

const suffixPatten = `\\/|['"]|\\s*\\)`;
function getRegExp(prefixPatten) {
return function (aliasName) {
return new RegExp(`(?:(${prefixPatten})\\s*['"]?\\s*)${aliasName}(\\/[^'";=)]*|['"]|\\s*\\))`, 'gm');
return new RegExp(`(?:(${prefixPatten})\\s*['"]?\\s*)${aliasName}(${suffixPatten})`, 'gm');
}

@@ -32,3 +33,3 @@ }

function replaceAll(file, dirname, aliasMap) {
const ext = path.extname(file.relative);
const ext = path.extname(file.relative);
const isStream = file.isStream();

@@ -67,8 +68,9 @@

const regExp = reg(alias);
const replacer = relative(dirname, aliasMap[alias]);
const subReg = new RegExp(`${alias}(${suffixPatten})`);
const replacer = `${relative(dirname, aliasMap[alias])}$1`;
if (isStream) {
file.contents = file.contents.pipe(replace(regExp, (match) => match.replace(alias, replacer)));
file.contents = file.contents.pipe(replace(regExp, (match) => match.replace(subReg, replacer)));
} else {
file.contents = Buffer.from(String(file.contents).replace(regExp, (match) => match.replace(alias, replacer)));
file.contents = Buffer.from(String(file.contents).replace(regExp, (match) => match.replace(subReg, replacer)));
}

@@ -75,0 +77,0 @@ });

{
"name": "gulp-path-alias",
"version": "1.0.1",
"version": "1.0.2",
"description": "path alias",

@@ -5,0 +5,0 @@ "main": "index.js",

# gulp-path-alias ![build](https://img.shields.io/badge/build-passing-green)
别名路径替换
`gulp` 路径别名

@@ -10,2 +10,3 @@ ## Install

## Usage
配置 `gulp task`
```js

@@ -26,3 +27,21 @@ const gulp = require('gulp');

```
在 `js` 使用:(支持 `js`、`ts`、`wxs`)
```js
import foo from '@libs/foo';
require('@libs/foo');
```
在 `html` 使用:(支持 `html`、`wxml`)
```html
<img src="@assets/img/bg.png">
```
在 `css`:(支持 `css`、`less` 等)
```css
@import "@assets/css/var.less";
.bg {
background-image: url(@assets/img/bg.png);
}
```
## API

@@ -34,9 +53,9 @@ ### alias(options)

##### cwd
Type: `string`
Type: `string`
Default: `process.cwd()`
##### paths
Type: `object`
Type: `object`
Default: `{}`
Path alias map.