{"id":13487201,"url":"https://github.com/mdsb100/gulp-wxa-copy-npm","last_synced_at":"2025-04-13T12:10:42.564Z","repository":{"id":57259531,"uuid":"83047342","full_name":"mdsb100/gulp-wxa-copy-npm","owner":"mdsb100","description":"微信小程序gulp插件，解决npm包管理和babel-runtime","archived":false,"fork":false,"pushed_at":"2017-08-05T05:35:36.000Z","size":17,"stargazers_count":52,"open_issues_count":1,"forks_count":5,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-27T03:12:03.182Z","etag":null,"topics":["gulp-plugin","npm-package","wxapp"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mdsb100.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-02-24T14:06:17.000Z","updated_at":"2022-09-17T18:43:47.000Z","dependencies_parsed_at":"2022-08-25T03:54:04.257Z","dependency_job_id":null,"html_url":"https://github.com/mdsb100/gulp-wxa-copy-npm","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mdsb100%2Fgulp-wxa-copy-npm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mdsb100%2Fgulp-wxa-copy-npm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mdsb100%2Fgulp-wxa-copy-npm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mdsb100%2Fgulp-wxa-copy-npm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mdsb100","download_url":"https://codeload.github.com/mdsb100/gulp-wxa-copy-npm/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248710445,"owners_count":21149190,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["gulp-plugin","npm-package","wxapp"],"created_at":"2024-07-31T18:00:56.528Z","updated_at":"2025-04-13T12:10:42.533Z","avatar_url":"https://github.com/mdsb100.png","language":"JavaScript","funding_links":[],"categories":["工具"],"sub_categories":[],"readme":"# gulp-wxa-copy-npm\n微信小程序gulp插件，解决npm包管理和babel-runtime。可以使用诸如ES7，moment等。\n\n在package.json加入\"babel-plugin-transform-runtime\"，在babel配置的plugins加入\"transform-runtime\"。这样就可以直接使用Promise,Map,Symbol等。\n\n如果想要使用async await，甚至是Decorator，具体只要参考babel配置就可以了。\n\n## Usage\nIn gulpfile.js\n```javascript\nconst gulp = require(\"gulp\");\nconst babel = require(\"gulp-babel\");\nconst gwcn = require('gulp-wxa-copy-npm');\nconst sourcemaps = require('gulp-sourcemaps');\n\ngulp.task('babel', () =\u003e\n    let knownOptions = {};\n\n    let options = minimist(process.argv.slice(2), knownOptions);\n    //config.babel\n    gulp.src('src/**/*.js')\n        .pipe(sourcemaps.init())\n        .pipe(log('Babeling'))\n        .pipe(babel({\n          \"presets\": [\n            \"es2015\",\n            \"stage-0\"\n          ],\n          \"plugins\": [\n            \"transform-export-extensions\",\n            \"syntax-export-extensions\",\n            \"transform-runtime\"\n          ]\n        }))\n        .pipe(gwcn(options))\n        .pipe(sourcemaps.write('.'))\n        .pipe(gulp.dest(config.dest));\n);\n\n```\n\n在代码中:\n```javascript\nconst moment = require('moment'); //NPM\nconst util = require('./util');\n```\n```javascript\nimport moment from 'moment' //NPM\n\nimport config from './config'\nimport {fetch} from '../common'\n```\n\n注意项目中的代码一定要使用```require('./util')```或```require('../common/page')```这种形式。\n\n## Installation\n```shell\n$ npm install gulp-wxa-copy-npm --save-dev\n```\n\n## Why\n首先感谢[labrador](https://github.com/maichong/labrador)和[wepy](https://github.com/wepyjs/wepy)参考了其中一些代码。这2个库很优秀！但是限制了我们。我们可以自己建gulpfile来使用stylus，imagemin等。可是最大的诉求是想用NPM包管理和ES7，没有这样的一个gulp插件。所以我就做了一个。\n\n\n但是自由是有代价的，很多东西你需要自己写。\n\n## Directory\n```\n|- dist\n|- src\n|- gulpfile.js\n\\- package.json\n```\n\n## Options\n- ```gwcn-src```默认是```'src'```。表示的是：源目录夹名。\n- ```gwcn-dest```默认是```'dist'```。表示的是：输出目录夹名。\n- ```node_modules```默认是```'../node_modules'```。表示的是：源目录和node_modules相对路径。\n- ```gwcn-log```默认是```false```。表示的是：是否输出log。\n- ```plugins```。数组。\n\n## Plugin Example\n```javascript\nconst guglify = through.obj(function(file, enc, callback) {\n    let code = file._contents.toString(enc);\n    let result = uglify.minify(code, {\n        fromString: true\n    });\n    file._contents = new Buffer(result.code);\n    callback(null, file);\n});\n\nconst task_babel_release = function() {\n    let knownOptions = {};\n\n    let options = minimist(process.argv.slice(2), knownOptions);\n    options.plugins = [(code, destPath, {file, enc, callback}) =\u003e uglify.minify(code, {\n        fromString: true\n    }).code];\n\n    //{file, enc, callback} 和through的保持一致\n\n    return gulp.src(config.js)\n        .pipe(log('Babeling'))\n        .pipe(babel(config.babel))\n        .pipe(guglify)\n        .pipe(gwcn(options))\n        .pipe(gulp.dest(config.dest));\n};\n\n```\n\n## Issues\n目前版本还是0.1.3，没有经过充分测试。欢迎大家提bug和pull request！\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmdsb100%2Fgulp-wxa-copy-npm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmdsb100%2Fgulp-wxa-copy-npm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmdsb100%2Fgulp-wxa-copy-npm/lists"}