微信小程序里导出 node_modules 包工具-演道网

本网站用的阿里云ECS,推荐大家用。自己搞个学习研究也不错
The tool is used to export packages in your project.

For Gulp, visit: https://github.com/HaoyCn/gulp-pkg-export

Here is a basic example:

'use strict';

const pkgExport = require('pkg-export');
// `rewriteRequire` accepts a string which is an absolute path to a script file.
// It looks `require()` up in scripts, find the required packages and rewrite the `require()`.
// Return an array which contains all of them.
const rewriteRequire = pkgExport({
    // String.
    // The basic directory of scripts
    base: 'src',
    // String.
    // The directory where node modules will be put
    npm: 'js/npm',
    // Array.
    // A list of package names. If a package cannot be found and it's in the list, the tool won't give a warning
    ignore: ['fs'],
    // Function. Optional.
    // The contents of files those aren't in 'node_modules' will be compiled by this function
    // Here is an example to see how to transform codes with babel
    compiler: function(content) {
        return require('babel-core').transform(content, {
            presets: ['es2015', 'stage-0'],
            plugins: ['transform-runtime']
        }).code;
    },
    // Function. Optional.
    // if a package cannot get resolved, this function will be called with an object which has `src` and `require` properties
    warn: console.warn
});

const arr = rewriteRequire(__dirname + '/src/index.js');

arr.forEach(function(file) {
    // the relative path
    console.log(file.dest);
    // the compiled codes
    console.log(file.content);

    // do something else
});

转载自演道,想查看更及时的互联网产品技术热点文章请点击http://go2live.cn

未经允许不得转载:演道网 » 微信小程序里导出 node_modules 包工具-演道网

赞 (0)
分享到:更多 ()

评论 0

评论前必须登录!

登陆 注册