# gulp-msapp-require

> Require npm module or common module, for Wechat miniapp

Latest version **3.2.5** (published 2018-05-21) · ISC license · 0 weekly downloads

## Install

```sh
npm install gulp-msapp-require
pnpm add gulp-msapp-require
yarn add gulp-msapp-require
bun add gulp-msapp-require
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.2.5 |
| Published | 2018-05-21 |
| First published | 2018-03-14 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 12 |
| Unpacked size | 21.6 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 3 |
| Author | rbinwu |
| Maintainers | rbinwu |

## Links

- npm: https://www.npmjs.com/package/gulp-msapp-require
- Repository: https://github.com/Rbin-life/gulp-msapp-require
- Homepage: https://github.com/Rbin-life/gulp-msapp-require#readme
- Issues: https://github.com/Rbin-life/gulp-msapp-require/issues
- npm.io page: https://npm.io/package/gulp-msapp-require

## Dependencies (12)

- [vinyl](https://npm.io/package/vinyl.md) ^2.1.0
- [lodash](https://npm.io/package/lodash.md) ^4.17.5
- [babylon](https://npm.io/package/babylon.md) ^6.18.0
- [fs-extra](https://npm.io/package/fs-extra.md) ^5.0.0
- [through2](https://npm.io/package/through2.md) ^2.0.3
- [babel-core](https://npm.io/package/babel-core.md) ^6.26.0
- [vinyl-file](https://npm.io/package/vinyl-file.md) ^3.0.0
- [babel-types](https://npm.io/package/babel-types.md) ^6.26.0
- [plugin-error](https://npm.io/package/plugin-error.md) ^1.0.1
- [babel-traverse](https://npm.io/package/babel-traverse.md) ^6.26.0
- [babel-generator](https://npm.io/package/babel-generator.md) ^6.26.1
- [enhanced-resolve](https://npm.io/package/enhanced-resolve.md) ^4.0.0

## Recent versions

- 3.2.5 (latest) — 2018-05-21
- 3.2.4 — 2018-05-15
- 3.2.3 — 2018-05-15
- 3.1.3 — 2018-05-11
- 3.0.3 — 2018-05-09
- 3.0.2 — 2018-05-09
- 3.0.1 — 2018-05-07
- 3.0.0 — 2018-05-07
- 2.0.0 — 2018-03-27
- 1.0.4 — 2018-03-22
- 1.0.3 — 2018-03-20
- 1.0.2 — 2018-03-14
- 1.0.1 — 2018-03-14
- 1.0.0 — 2018-03-14

## README

# gulp-msapp-require

Require npm module or custom-common module, for Wechat miniapp.

## Install

```
npm install gulp-msapp-require --save-dev
```

## Usage


```

var gulp = require("gulp")
var msappRequire = require("gulp-msapp-require")

// msappRequire(options)
gulp.task("release", function() {
    gulp.src(["src/**/*"])
    .pipe(gulp.dest("./dist")) // gulp-msapp-require will change the origin file's dependency path, the best way is building in a new folder
    .on("end", function() {
        gulp.src(["dist/**/*"])
        .pipe(msappRequire({
            output: path.resolve(__dirname, "./dist/common"),
            resolve: {
                extensions: [".js", ".json"],
                modules: [path.resolve(__dirname, "./custom"), path.resolve(__dirname, "../node_modules")],
                alias: {
                    utils: "./test/a/index.js",
                    math: "sub/math"
                }
            },
            cache: true
        }))
        .pipe(gulp.dest("./dist"))
    })
})

// msappRequire.manifest(options)
gulp.task("manifest-release", function() {
    gulp.src(["src/**/*"])
    .pipe(gulp.dest("./cdist"))
    .on("end", function() {
        gulp.src(["cdist/**/*"])
        .pipe(msappRequire.manifest({
            output: path.resolve(__dirname, "./cdist/common"),
            resolve: {
                extensions: [".js", ".json"],
                modules: [path.resolve(__dirname, "./custom"), path.resolve(__dirname, "../node_modules")],
                alias: {
                    utils: "./test/a/index.js",
                    math: "sub/math"
                }
            },
            cache: path.resolve(__dirname, "./src/depends.json"),
            manifest: "msapp-require-manifest.json"
        }))
        .pipe(gulp.dest("./cdist"))
    })
})
```


## API

### msappRequire(options)
Analyze the npm module or custom-common module that the code relies on, and then copy to the corresponding directory, and convert the corresponding dependent path in the code.

### msappRequire.manifest(options)
Analyze the npm module or custom-common module that the code relies on, and then copy to the corresponding directory, and map the corresponding dependency path to the manifest.json. **(It does not convert the dependent path in the code)**

#### options

Type: `Object`

##### options.output
Type: `String`<br>

##### options.resolve
Type: `Object`

| Field                    | Default                     | Description                                                                        |
| ------------------------ | --------------------------- | ---------------------------------------------------------------------------------- |
| alias                    | []                          | A list of module alias configurations or an object which maps key to value |
| aliasFields              | []                          | A list of alias fields in description files |
| cacheWithContext         | true                        | If unsafe cache is enabled, includes `request.context` in the cache key  |
| descriptionFiles         | ["package.json"]            | A list of description files to read from |
| enforceExtension         | false                       | Enforce that a extension from extensions must be used |
| enforceModuleExtension   | false                       | Enforce that a extension from moduleExtensions must be used |
| extensions               | [".js", ".json", ".node"]   | A list of extensions which should be tried for files |
| mainFields               | ["main"]                    | A list of main fields in description files |
| mainFiles                | ["index"]                   | A list of main files in directories |
| modules                  | ["node_modules"]            | A list of directories to resolve modules from, can be absolute path or folder name |
| unsafeCache              | false                       | Use this cache object to unsafely cache the successful requests |
| plugins                  | []                          | A list of additional resolve plugins which should be applied |
| symlinks                 | true                        | Whether to resolve symlinks to their symlinked location |
| cachePredicate           | function() { return true }; | A function which decides whether a request should be cached or not. An object is passed to the function with `path` and `request` properties. |
| moduleExtensions         | []                          | A list of module extensions which should be tried for modules |
| resolveToContext         | false                       | Resolve to a context instead of a file |
| fileSystem               |                             | The file system which should be used |
| resolver                 | undefined                   | A prepared Resolver to which the plugins are attached |

##### options.cache
Type: `Boolean|String`
Default: false<br>

Using cache, building faster.

---
_Source: https://npm.io/package/gulp-msapp-require · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
