@wannasky/cli
前端打包cli工具
Last updated 8 months ago by wannasky .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @wannasky/cli 
SYNC missed versions from official npm registry.

@wannasky/cli

脚手架工具,以后慢慢维护

wans server

  1. wans server config.js

    指定config.js配置文件启动,不指定调用根目录wans.config.js

  2. wans server --help

    查看配置帮助信息

wans jshint

  1. wans jshint config.js

    指定config.js配置文件启动,不指定调用根目录wans.config.js

  2. wans jshint --help

    查看配置帮助信息

wans compress

  1. wans compress config.js

    指定config.js配置文件启动,不指定调用根目录wans.config.js

  2. wans compress --help

    查看配置帮助信息

示例配置如下:

module.exports = {

    //端口号
    port: 8080,

    //根目录
    root: './public',
    
    //jshint配置
    jsHint: {
        files: ['src/test/**/*.js', 'src/index.js'],
        exclude: ['src/test/**/*.spec.js', 'src/test/**/*.min.js'],
        options: {
            eqeqeq: true
            //...
        }
    },
    
    //压缩相关配置
    compress: {
        src: './test/__test__/compress/src',
        dist: './test/__test__/compress/dist',
        files: ['**/*.js', '/**/*.css', '**/*.scss'],
        exclude: ['/**/*.min.js', '/lib/**/*.js'],
        framework: ['angular'],
        filename: {
            'css': '../css/[name].[ext]',
            'js': '[name].min.[ext]'
        }
    },

    //本地静态资源路径重定向
    local: {
        '^/test/': '../test/',
    },

    //代理设置
    proxy: {
        '^/5aV1bjqh_Q23odCf': 'https://ss0.bdstatic.com/',
        '/api/test': {
            target: 'https://test.dyn.com',
            headers: {
                host: 'aa.cc.com'
            }
        }
    },

    //路由设置
    router: {

        '/router/:id': {
            get: (req, res, query, mock) => {
                console.log('query', query);
                res.json(mock(mock.object({
                    name: 'wannasky',
                    age: 25,
                    books: mock.array({
                        length: mock.random(5, 10),
                        item: mock.object({
                            title: mock.text('book-', mock.index),
                            isbn: mock.random(1000, 2000, true)
                        })
                    })
                })))
            }
        },

        '/wannasky/test': {
            post: (req, res, query, mock) => {
                console.log('query', query);
                res.json({success: true})
            }
        }
    },
    
    //测试json目录
    //当路由,代理,静态资源都获取不到时,再尝试获取.json后缀的文件
    testJsonDir: './__test__/json'
}

代理数据保存并离线使用

通过配置 proxySave = true并指定testJsonDir

module.exports = {
    port: '8888',
    root: './',
    proxy: {
        '/': {      // 这里是把所有请求都走代理
            target: 'https://xx.xxx.xx.xx'
        }
    },
    proxySave: true,    // 代理的数据保存本地
    
    testJsonDir: '__test'   // 代理数据保存的文件目录
}

通过以上配置会在__test目录下生成代理的文件及映射关系(manifest.json),然后通过配置 useManifest来使用

module.exports = {
    port: '8888',
    root: './',
    useManifest: true,  // 使用manifest.json配置来完成代理    
    testJsonDir: '__test'   // 代理数据保存的文件目录
}

options参数支持说明

{
    css: {
        // sourceMap: true   //编译后的css所在目录
        // souceMap: '../map'  // 相对dist配置目录
    },
    compress: {
        drop_console: false,  //见 https://www.npmjs.com/package/uglify-js
    }
}

local配置详情

默认会建立symbol link,可通过 #copy改变默认行为为复制,再通过#watch(依附于#copy)来进行文件双向变更检测 eg:


{
    local: {
        'web/test': 'E:\\repo\\test#copy',      // 仅复制 
        'web/one': 'E:\\repo\\one#copy#watch'   // 文件复制及文件双向监听
    }    
}

router配置详情

get或者post对应的方法参数有req, res, query, mock;其中 res包括如下方法:

  • res.json(value: {}) 用来返回json内容

  • res.renderUrl(url: string) 返回指定文件内容,Content-Type会根据文件后缀自动匹配

  • res.next() 当条件判断失败后,可以主动调用,可模拟 nginx $try_files, eg:

router: {
    '/project/dist/module/': {
        get: (req, res) => {
            if(req.url === '/project/dist/module/' || !path.parse(req.url).ext) {
                res.renderUrl('./project/dist/index.html')
            } else {
                res.next();
            }
        }
    }
}

LICENSE

MIT

Current Tags

  • 1.7.11                                ...           latest (8 months ago)

56 Versions

  • 1.7.11                                ...           8 months ago
  • 1.7.10                                ...           9 months ago
  • 1.7.9                                ...           9 months ago
  • 1.7.8                                ...           9 months ago
  • 1.7.7                                ...           a year ago
  • 1.7.6                                ...           a year ago
  • 1.7.5                                ...           a year ago
  • 1.7.4                                ...           a year ago
  • 1.7.3                                ...           a year ago
  • 1.7.2                                ...           a year ago
  • 1.7.1                                ...           a year ago
  • 1.7.0                                ...           a year ago
  • 1.6.9                                ...           a year ago
  • 1.6.8                                ...           a year ago
  • 1.6.7                                ...           a year ago
  • 1.6.6                                ...           a year ago
  • 1.6.5                                ...           a year ago
  • 1.6.4                                ...           a year ago
  • 1.6.3                                ...           a year ago
  • 1.6.2                                ...           a year ago
  • 1.6.1                                ...           a year ago
  • 1.6.0                                ...           a year ago
  • 1.5.9                                ...           a year ago
  • 1.5.8                                ...           a year ago
  • 1.5.7                                ...           a year ago
  • 1.5.6                                ...           a year ago
  • 1.5.5                                ...           a year ago
  • 1.5.4                                ...           a year ago
  • 1.5.3                                ...           a year ago
  • 1.5.2                                ...           a year ago
  • 1.5.0                                ...           a year ago
  • 1.4.2                                ...           a year ago
  • 1.4.1                                ...           a year ago
  • 1.4.0                                ...           a year ago
  • 1.3.7                                ...           a year ago
  • 1.3.6                                ...           2 years ago
  • 1.3.5                                ...           2 years ago
  • 1.3.3                                ...           2 years ago
  • 1.3.2                                ...           2 years ago
  • 1.3.1                                ...           2 years ago
  • 1.2.7                                ...           2 years ago
  • 1.2.6                                ...           2 years ago
  • 1.2.5                                ...           2 years ago
  • 1.2.4                                ...           2 years ago
  • 1.2.3                                ...           2 years ago
  • 1.2.2                                ...           2 years ago
  • 1.1.2                                ...           2 years ago
  • 1.1.1                                ...           2 years ago
  • 1.1.0                                ...           2 years ago
  • 1.0.6                                ...           2 years ago
  • 1.0.5                                ...           2 years ago
  • 1.0.4                                ...           2 years ago
  • 1.0.3                                ...           2 years ago
  • 1.0.2                                ...           2 years ago
  • 1.0.1                                ...           2 years ago
  • 1.0.0                                ...           2 years ago
Maintainers (1)
Downloads
Today 0
This Week 1
This Month 1
Last Day 1
Last Week 0
Last Month 59
Dependencies (18)
Dev Dependencies (2)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |