在生产模式下,我的 webpack 缩小了 .js (正如它应该的那样)。但我还需要缩小我的 .css,为此我必须使用 OptimizeCssAssetsPlugin。当我使用它时,它会缩小我的 .css 但我的 .js 保持未缩小状态。
我的猜测是,当我使用优化(“模块”和“插件”旁边)时,js 会缺少一些东西,因为没有整个“优化”块它就无法工作。但它是什么?为什么?
const path = require('path');
const HtmlWebPackPlugin = require("html-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const WriteFilePlugin = require("write-file-webpack-plugin");
const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin');
module.exports = {
entry: './src/index.js',
output: {
path: path.join(__dirname, '/dist'),
filename: 'bundle.js',
publicPath: '/'
},
devtool: 'source-map',
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: "babel-loader"
}
},
{
test: /\.(sa|sc|c)ss$/,
exclude: /node_modules/,
use: [MiniCssExtractPlugin.loader, "css-loader", "sass-loader"]
}
]
},
plugins: [
new …Run Code Online (Sandbox Code Playgroud) Webpack 检查函数的使用情况并删除(作为死代码)“未使用”的函数。但是,如果我在 HTML 中使用该函数,则如果没有脚本调用该函数,该函数将被删除。
例如,我有 script.js:
function doSomething() {
console.log("clicked button");
}
function explicitUsedFunction() {
console.log("Hey, function called!");
}
explicitUsedFunction();
Run Code Online (Sandbox Code Playgroud)
和index.html:
<html>
<head>
<title>Test</title>
<script src="script.js"></script>
</head>
<body>
<button onclick="doSomething()">Button</button>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
doSomething 函数由 onclick 按钮事件使用。
这是我的 webpack.config.js:
const path = require('path');
const TerserMinimizer = require('terser-webpack-plugin');
module.exports = {
mode: 'production',
entry: ["./script.js"],
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'bundle.js'
},
optimization: {
minimize: true,
minimizer: [
new TerserMinimizer({
terserOptions: {
keep_classnames: true,
keep_fnames: true
}
})
]
}
}; …Run Code Online (Sandbox Code Playgroud) 我需要缩小服务器上的代码。它告诉我npm run build做所有缩小的事情
但在我的服务器上(当然我不是通过访问它localhost)它显示了所有代码。我正在mavennpm run build中做pom.xml。我的包 json 包含反应脚本的实际版本。

所有代码均由 nginx 提供。
好的,我已经看到了
When does create-react-app obfuscate or minify code?
这个GENERATE_SOURCEMAP=false 问题
并阅读这个https://www.html5rocks.com/en/tutorials/developertools/sourcemaps/#toc-howgenerate
它告诉我所以Developer tools (currently WebKit nightly builds, Google Chrome, or Firefox 23+) can parse the source map automatically and make it appear as though you're running unminified and uncombined files.
它告诉我源映射是我看到我的代码的原因照原样。
还有一个没有 devTools 的 Firefox 浏览器,我在其中关闭了源映射
并且...它按原样向我显示了代码!
npm run build 尽管“使构建缩小”,为什么它仍然向我显示代码?请告诉我哪里不好以及如何解决?顺便说一句,到处都写着 *.env 应该位于根目录中。整个项目的根目录还是仅前端文件夹?
我们都知道xHTML/CSS和JS缩小和压缩有利于大型流量站点.
看看下面的代码:
include("template.funcs.php");
include("country-redirect.php");
if(($country=='PL')||($country=='POL'))
{
header('Location: index_pol.php');
exit();
}
$include_path = './global_php/';
$page = "couture";
include $include_path."shop.inc.php";
$movie_num = 1 ;
Run Code Online (Sandbox Code Playgroud)
现在看看minifed版本:
include("template.funcs.php");include("country-redirect.php");
if(($country=='PL')||($country=='POL')){header('Location: index_pol.php');
exit();}
$include_path='./global_php/';$page="couture";include $include_path."shop.inc.php";
$movie_num=1;
Run Code Online (Sandbox Code Playgroud)
您认为哪一个更快 - 一般来说,我也想开始缩小我的编程,小的var和字符串名称,如$ a而不是$ apple,并试图删除尽可能多的额外字符.PHP编译器会像压缩块还是间隔一块?
我的问题不是关于css,而是关于标签之间的html页面内的空格等.
是否有任何理由页面http://m.aol.com/portal/在html代码中包含这么多空格(请查看http://m.aol.com/portal/页面的源代码)?我错过了什么吗?
如何在移动版本的页面上出现这么多空格?有什么猜测?为什么和为什么?
这是一个基本的东西,但我发现值得与大家分享.我观察到代码压缩实用程序改变了代码片段,其中写入条件,
if(document.getElementById('foo').value == '6')
Run Code Online (Sandbox Code Playgroud)
至
if('6' == document.getElementById('foo').value)
Run Code Online (Sandbox Code Playgroud)
这会有什么帮助?
是我的index.html:
<script src="/app/bower_components/angular/angular.js"></script>
<script src="/app/bower_components/angular-route/angular-route.js"></script>
<script src="/app/bower_components/angular-resource/angular-resource.js"></script>
<script src="/app/bower_components/angular-cookies/angular-cookies.js"></script>
<script src="/app/bower_components/angular-sanitize/angular-sanitize.js"></script>
Run Code Online (Sandbox Code Playgroud)
在我的快速配置中,我有:
app.use(minify());
app.use('/app', express["static"](path.resolve('app')));
app.use('/public', express["static"](path.resolve('public')));
Run Code Online (Sandbox Code Playgroud)
如果我缩小,我的AngularJS代码中出错:
Failed to instantiate module appApp due to: [$injector:unpr] Unknown provider: e
Run Code Online (Sandbox Code Playgroud)
如果我不缩小,一切都很好.我究竟做错了什么?
我正在使用django-compressor来压缩css文件.
我按照http://django-compressor.readthedocs.org/en/latest/quickstart/中的解释做了.
我更改了我的模板文件,如下所示:
{% load staticfiles %}
{% load compress %}
<!DOCTYPE html>
<html lang="en">
<head>
{% compress css %}
<link href="{% static "crsq/css/zippednewsapp/bootstrap.readable.min.css" %}" rel="stylesheet">
<link href="{% static "crsq/css/zippednewsapp/zippednewsapp.css" %}" rel="stylesheet">
<link rel="stylesheet" href="{% static "crsq/css/zippednewsapp/typeahead.css" %}"/>
{% endcompress %}
</head>
.....
Run Code Online (Sandbox Code Playgroud)
我没有看到任何变化.没错.文件未压缩.我该如何改变?
在我的设置文件中:
DEBUG = False
TEMPLATE_DEBUG = False
STATIC_ROOT = ''
STATIC_URL = '/static/'
STATICFILES_DIRS = (
)
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
'compressor.finders.CompressorFinder',
)
Run Code Online (Sandbox Code Playgroud)
感谢任何帮助.谢谢
我正在尝试使用带HtmlWebpackPlugin插件的Webpack缩小我的html文件。我设法将index.html文件制作到dist加载程序中,但是在缩小文件时遇到了一些麻烦。
dist/
node_modules/
src/
ejs/
js/
css/
server.js
webpack.config.js
package.js
Run Code Online (Sandbox Code Playgroud)
webpack.config.js:
var HtmlWebpackPlugin = require('html-webpack-plugin');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
module.exports = {
entry: './src/js/index.js',
devtool: 'source-map',
output: {
publicPath: '/dist/'
},
module: {
rules: [
{
test: /\.ejs$/,
use: ['ejs-loader']
},
{
test: /\.css$/,
use: ExtractTextPlugin.extract({
use: [{
loader: 'css-loader',
options: {
url: false,
minimize: true,
sourceMap: true
}
}]
})
}
]
},
plugins: [
new HtmlWebpackPlugin({
template: './src/ejs/index.ejs',
minify: true
}),
new …Run Code Online (Sandbox Code Playgroud) minify ×10
javascript ×5
webpack ×3
html ×2
angularjs ×1
compression ×1
css ×1
django ×1
express ×1
nuxt.js ×1
optimization ×1
php ×1
python ×1
reactjs ×1
static ×1