У меня есть webpack 4.17.1, работающий с моим SPA в среде Dev.
Теперь я хочу упаковать для Production.
Он запускается с помощью этой команды в средстве выполнения задач Visual Studio:
C:\Dev\Traken.app\Traken.5\Dev\Traken\Traken> cmd /c SET NODE_ENV=production&& webpack --color
Однако кажется, что среда не выбирается WebPack, поскольку эта команда возвращает undefined
console.log("mode=", argv.mode);
Это webpack.config.js:
const path = require("path");
const webpack = require("webpack");
const { AureliaPlugin, ModuleDependenciesPlugin, GlobDependenciesPlugin } = require("aurelia-webpack-plugin");
const ExtractTextPlugin = require("extract-text-webpack-plugin");
const extractCSS = new ExtractTextPlugin("vendor.css");
const bundleOutputDir = "./wwwroot/dist";
module.exports = (env, argv) => {
if ((!argv || !argv.mode) && process.env.ASPNETCORE_ENVIRONMENT === "Development") {
argv = { mode: "development" };
}
console.log("mode=", argv.mode);
const isDevBuild = argv.mode !== "production";
const cssLoader = { loader: isDevBuild ? "css-loader" : "css-loader?minimize" };
return [{
target: "web",
mode: isDevBuild ? "development" : "production",
entry: { "app": ["es6-promise/auto", "aurelia-bootstrapper"] },
resolve: {
extensions: [".ts", ".js"],
modules: ["ClientApp", "node_modules"],
},
output: {
path: path.resolve(bundleOutputDir),
publicPath: "/dist/",
filename: "[name].js",
chunkFilename: "[name].js"
},
module: {
rules: [
{ test: /\.ts$/i, include: [/ClientApp/, /node_modules/], use: "awesome-typescript-loader" },
{ test: /\.html$/i, use: 'html-loader' },
{ test: /\.css$/i, use: isDevBuild ? 'css-loader' : 'css-loader?minimize' },
{ test: /\.(png|jpg|jpeg|gif|svg)$/, use: 'url-loader?limit=25000' },
{ test: /\.woff2(\?v=[0-9]\.[0-9]\.[0-9])?$/, loader: 'url-loader', query: { limit: 10000, mimetype: 'application/font-woff2' } },
{ test: /\.woff(\?v=[0-9]\.[0-9]\.[0-9])?$/, loader: 'url-loader', query: { limit: 10000, mimetype: 'application/font-woff' } },
{ test: /\.(ttf|eot|svg|otf)(\?v=[0-9]\.[0-9]\.[0-9])?$/, loader: 'file-loader' },
{ test: /\.(cur|ani)$/, loader: 'file-loader' }
]
},
optimization: {
splitChunks: {
cacheGroups: {
commons: {
test: /[\\/]node_modules[\\/]/,
name: "vendor",
chunks: "all"
}
}
}
},
devtool: isDevBuild ? "source-map" : false,
performance: {
hints: false
},
plugins: [
new webpack.ProvidePlugin({
'Promise': 'bluebird'
}),
new ModuleDependenciesPlugin({
"aurelia-orm": [
"./component/association-select",
"./component/view/bootstrap/association-select.html",
"./component/view/bootstrap/paged.html",
"./component/paged"],
"aurelia-authentication": ["./authFilterValueConverter"]
}),
new webpack.DefinePlugin({ IS_DEV_BUILD: JSON.stringify(isDevBuild) }),
new AureliaPlugin({ aureliaApp: "boot" }),
new GlobDependenciesPlugin({ "boot": ["ClientApp/**/*.{ts,html}"] }),
new ModuleDependenciesPlugin({}),
extractCSS
]
}];
};