在无服务器的webpack.config.js中获取处理程序入口点

时间:2019-03-23 06:40:18

标签: webpack aws-lambda serverless

在webpack.config.js中,我正在使用'serverless-webpack',它使我能够设置entry: slsw.lib.entries来自动确定正确的处理程序入口点,但是我正在使用inq-webpack-plugin-copy,我只想在一个堆栈/服务中应用此插件,该怎么办?

    const path = require('path');
    const slsw = require('serverless-webpack');
    const WebpackPluginCopy = require("inq-webpack-plugin-copy");
    module.exports = {
        entry: slsw.lib.entries,
        target: 'node',
        module: {
            loaders: [{
                test: /\.js$/,
                loaders: ['babel'],
                include: __dirname,
                exclude: /..\..\node_modules/,
            },
            {
                test: /\.json$/,
                loaders: ['json']
            }, {
                test: /\.node$/,
                loaders: ['node-loader'],
            }]
        },
        externals: [
            (function () {
                var IGNORES = [
                    'electron'
                ];
                return function (context, request, callback) {
                    if (IGNORES.indexOf(request) >= 0) {
                        return callback(null, "require('" + request + "')");
                    }
                    return callback();
                };
            })()
        ],
   // I WANT THIS TO BE EXECUTED CONDITIONALLY.
        plugins: [
            new WebpackPluginCopy([
                {
                    from: "bin/wkhtmltopdf",
                    to: "wkhtmltopdf",
                    toType: "file",
                    copyPermissions: true
                }
            ])
        ]
    };

结构:

-webpack.config.js
-services
    -service1
       -serverless.yml
       -lambdas

    -service2

1 个答案:

答案 0 :(得分:0)

我想要一种仅将webpack插件安装到一项服务的方法,所以对我有用的是我为该堆栈创建了一个单独的webpack.config.js文件。例如service1目录。但我不想将整个node_modules目录复制到该目录中。并设置node_modules路径

module: {
    loaders: [
        {
            test: /\.js$/,
            loaders: ['babel'],
            //This points to the root directory so we can get nodemodules and other stuff
            include: path.resolve(__dirname, '../../../'),
            exclude: /node_modules/,
        },