webpack.config.js中的env param导出函数而不是对象

时间:2018-01-15 21:39:32

标签: asp.net webpack

.NET Core创建以下webpack.config.js

const path = require("path");
const webpack = require("webpack");
const merge = require("webpack-merge");
const CheckerPlugin = require("awesome-typescript-loader").CheckerPlugin;

module.exports = (env) => {
    // Configuration in common to both client-side and server-side bundles
    const isDevBuild = !(env && env.prod);
    const sharedConfig = {
        stats: { modules: false },
        context: __dirname,
        resolve: { extensions: [ ".js", ".ts" ] },
        output: {
            filename: "[name].js",
            publicPath: "dist/" // Webpack dev middleware, if enabled, handles requests for this URL prefix
        },
        module: {
            rules: [
                { test: /\.ts$/, include: /ClientApp/, use: isDevBuild ? ["awesome-typescript-loader?silent=true", "angular2-template-loader"] : "@ngtools/webpack" },
                { test: /\.html$/, use: "html-loader?minimize=false" },
                { test: /\.css$/, use: [ "to-string-loader", isDevBuild ? "css-loader" : "css-loader?minimize" ] },
                { test: /\.(png|jpg|jpeg|gif|svg)$/, use: "url-loader?limit=25000" }
            ]
        },
        plugins: [new CheckerPlugin()]
    };
// Configuration for client-side bundle suitable for running in browsers
    const clientBundleOutputDir = "./wwwroot/dist";
    const clientBundleConfig = merge(sharedConfig, {
        entry: { "main-client": "./ClientApp/boot.browser.ts" },
        output: { path: path.join(__dirname, clientBundleOutputDir) },
        plugins: [
            new webpack.DllReferencePlugin({
                context: __dirname,
                manifest: require("./wwwroot/dist/vendor-manifest.json")
            })
        ].concat(isDevBuild ? [
            // Plugins that apply in development builds only
            new webpack.SourceMapDevToolPlugin({
                filename: "[file].map", // Remove this line if you prefer inline source maps
                moduleFilenameTemplate: path.relative(clientBundleOutputDir, "[resourcePath]") // Point sourcemap entries to the original file locations on disk
            })
        ] : [
            // Plugins that apply in production builds only
                new webpack.optimize.UglifyJsPlugin(),

        ])
    });
return [clientBundleConfig];
};

我不知道我们可以导出function instead of an object。通过在命令行中执行 webpack ,我们调用上面的函数吗?我们如何以及在何处定义参数 env ?有没有办法看到它? console.log不会控制它,我无法添加断点...

1 个答案:

答案 0 :(得分:-1)

以下链接说明了所有内容:https://webpack.js.org/guides/environment-variables/