Webpack导出模块,如lodash

时间:2015-06-24 16:09:36

标签: webpack

Lodash导出这样的模块: var chunk = require('lodash/array/chunk');

我想创建一个以相同方式导出模块的库。因此,对于另一个项目,我只能导入我想要的模块:

var module1 = require('my-library/moduel1'); var module2 = require('my-library/module2'); var moduele3 = require('my-library/module3');

或与amd define(['my-library/moduel1', 'my-library/moduel2',''my-library/moduel3'], function ...)

所以我认为我的库配置不正确,它们是:

var path = require('path'),     
    webpack = require('webpack');

module.exports = {
    devtool: '#inline-source-map',
    resolve: {
        alias: {
            'my-library/module1' : path.resolve(__dirname, './lib/module1/index.js'),
            'my-library/module2' : path.resolve(__dirname, './lib/module2/index.js'),
            'my-library/module3' : path.resolve(__dirname, './lib/module3/index.js'),
        }
    },
    entry: {
        app: './lib/index.js'
    },
    output: {
        library: 'my-library',
        libraryTarget: 'amd',
        path: path.resolve(__dirname, 'dist'),
        filename: "my-library.js"
    },
    externals:{
        'lodash': '_'
    },
    plugins: [  
    ],
    module: {
        loaders: [
            { 
                test: "my-library/module1", 
                loader: "exports-loader"
            },
            { 
                test: "my-library/module2", 
                loader: "exports-loader"
            },
            { 
                test: "my-library/module3", 
                loader: "exports-loader"
            }
        ]
    }
}

我使用的是exports-loader而不是correclty吗?你也知道github上的任何例子吗? 感谢

0 个答案:

没有答案