gpt4 book ai didi

javascript - Webpack 4 - 没有正确缩小 css 和正确 uglify js

转载 作者:行者123 更新时间:2023-11-30 20:09:55 27 4
gpt4 key购买 nike

我已经为我的项目设置了 webpack。我想缩小 CSS 源。

这是 webpack.config.js:

var webpack = require('webpack');
const path = require('path');
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin');

module.exports = {
devtool: 'source-map',
mode: 'production',
entry: {
'target/web-resources/resources/lib/angular/angular.js': './node_modules/angular/angular.js',
'target/web-resources/resources/lib/angucomplete-alt/angucomplete-alt.js': './node_modules/angucomplete-alt/angucomplete-alt.js',
'target/web-resources/resources/lib/angucomplete-alt/angucomplete-alt.css': './node_modules/angucomplete-alt/angucomplete-alt.css',
},
module: {
rules: [
{
test: /\.css$/,
use: [
"style-loader",
"css-loader"
]
}
]
},
plugins: [
new MiniCssExtractPlugin({
filename: "[name].css",
chunkFilename: "[id].css"
})
],
optimization: {
minimizer: [
new UglifyJsPlugin({
cache: true,
parallel: true,
sourceMap: true
}),
new OptimizeCssAssetsPlugin({
assetNameRegExp: /\.min\.css$/g,
cssProcessor: require('cssnano'),
cssProcessorOptions: ['default', {discardComments: {removeAll: true}}],
canPrint: true
})
]
},
output: {
path: path.resolve(__dirname, '.'),
filename: '[name]'
}

};

但是它生成的 css 文件如下:https://pastebin.com/rWWWvkGG (没有预期的扩展名 .min.css - 只是 .css)

还有原始的 angucomplete-alt.js 文件,它有 27kB,它产生的文件是 167kB。看起来它包含的不仅仅是原始代码:https://pastebin.com/E87pzTh0

最佳答案

module: {
rules: [
{
test: /\.css$/,
use: [
MiniCssExtractPlugin.loader, // <---- this is missing
"css-loader"
]
}
]
},

关于javascript - Webpack 4 - 没有正确缩小 css 和正确 uglify js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52518214/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com