javascript – Webpack忽略统计选项
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了javascript – Webpack忽略统计选项,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含4132字,纯文字阅读大概需要6分钟。
内容图文
![javascript – Webpack忽略统计选项](/upload/InfoBanner/zyjiaocheng/789/a02720699a4e4a4ba705ffce55d760a9.jpg)
UPDATE
@Daniel Khoroshko的答案解决了我的统计问题.为了将来参考,webpack可以(至少)4种方式处理统计数据:
>将统计信息视为常规的Webpack选项https://webpack.js.org/configuration/stats/
>如果使用devServer,则必须将其放在该对象中(请参阅上面链接中的注释)
>如果使用Node API,则它必须位于回调函数中. https://webpack.js.org/api/node/#stats-object
>正如丹尼尔指出的那样,webpack-dev-middleware会覆盖统计数据,因此对象必须在https://github.com/webpack/webpack-dev-middleware#stats中
================================================
使用webpack 3.10我试图压制我得到的百万个extract-text-webpack-plugin日志.
我们正在使用webpack Node API.在我们的server.js中,我们的节点入口点,我们有:
// server.js
const app = express();
if (environment.isLocal) {
require('./webpackConfig')(app);
} else {
app.use(compression());
}
// other stuff
我们在webpack中使用节点:
// webpackConfig.js
const webpack = require('webpack');
const config = require('../webpack.config.dev');
module.exports = (app) => {
const compiler = webpack(config, (err, stats) => {
stats.toJson("none"); // none for brevity, but not working
});
app.use(require('webpack-dev-middleware')(compiler, {
noInfo: true,
publicPath: config.output.publicPath
}));
app.use(require('webpack-hot-middleware')(compiler));
};
最后,整个配置
// webpack.config.dev.js
module.exports = {
devtool: 'cheap-module-source-map',
entry: {
app: [
'eventsource-polyfill',
'webpack-hot-middleware/client?reload=true',
'./src/index'
]
},
target: 'web',
output: {
path: __dirname + '/dist',
publicPath: '/',
filename: '[name].js'
},
devServer: {
contentBase: './src'
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
new webpack.NoEmitOnErrorsPlugin(),
new ExtractTextPlugin('[name]-[hash].css'),
new HtmlWebpackPlugin({
title: 'annoying webpack',
template: './src/index.html',
alwaysWriteToDisk: true,
inject: false
}),
new HtmlWebpackHarddiskPlugin()
],
module: {
rules: [
{
test: /\.js$/,
enforce: 'pre',
loader: require.resolve('eslint-loader'),
options: {
failOnWarning: false,
failOnError: false
},
exclude: /node_modules|dist/
},
{
test: /\.js$/,
include: [path.join(__dirname, 'src')]
loader: 'babel-loader'
}
]
}
};
控制台输出
webpack building...
webpack built c22fd3ae797ecd55eccc in 7410ms
? ?wdm?: Hash: c22fd3ae797ecd55eccc
Version: webpack 3.10.0
Time: 7410ms
Asset Size Chunks
Chunk Names
app.js 2.53 MB 0 [emitted] [big]
app
app-c22fd3ae797ecd55eccc.css 125 kB 0 [emitted]
app
app.js.map 2.97 MB 0 [emitted]
app
app-c22fd3ae797ecd55eccc.css.map 4.71 kB 0 [emitted]
app
index.html 275 bytes [emitted]
[3] ./node_modules/react/react.js 56 bytes {0} {0} [built]
[100] ./node_modules/react-dom/index.js 59 bytes {0} {0} [built]
[107] ./node_modules/react-redux/es/index.js 230 bytes {0} {0}
[built]
.....
+ 867 hidden modules
Child html-webpack-plugin for "index.html":
Asset Size Chunks Chunk Names
index.html 568 kB 0
.....
? ?wdm?: Compiled successfully.
webpack built d7509fff9f1c995bf5ee in 7523ms
? ?wdm?: Hash: d7509fff9f1c995bf5ee
Version: webpack 3.10.0
Time: 7523ms
Asset Size Chunks
Chunk Names
app.js 2.53 MB 0 [emitted] [big]
app
app-d7509fff9f1c995bf5ee.css 125 kB 0 [emitted]
app
app.js.map 2.97 MB 0 [emitted]
app
app-d7509fff9f1c995bf5ee.css.map 4.71 kB 0 [emitted]
app
index.html 275 bytes [emitted]
[5] ./src/App.js 3.62 kB [built]
[6] ./src/store/configureStore.js 325 bytes [built]
.....
+ 867 hidden modules
Child html-webpack-plugin for "index.html":
Asset Size Chunks Chunk Names
index.html 568 kB 0
[0] ./node_modules/html-webpack-plugin/lib/loader.js!./src/index.html 646 bytes {0} [built]
[1] ./node_modules/lodash/lodash.js 540 kB {0} [built]
[2] (webpack)/buildin/global.js 509 bytes {0} [built]
[3] (webpack)/buildin/module.js 517 bytes {0} [built]
? ?wdm?: Compiled successfully.
解决方法:
关于统计选项webpack-dev-middleware和webpack-dev-server有自己的统计设置,我想这会覆盖webpack自己的设置.我建议尝试这个
app.use(require('webpack-dev-middleware')(compiler, {
noInfo: true,
publicPath: config.output.publicPath,
stats: 'errors-only'
}));
内容总结
以上是互联网集市为您收集整理的javascript – Webpack忽略统计选项全部内容,希望文章能够帮你解决javascript – Webpack忽略统计选项所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。