我最近升級到了Webpack 2,現在瀏覽器中的所有console.log都消失了,以及所有的redux-logger輸出,以及所有JavaScript錯誤和警告。使用Webpack控制console.log輸出2
我有兩個配置 - 開發和測試。它們幾乎是一樣的,但dev有console.logs,測試沒有。我如何在測試中啓用它們?
這裏的開發具有console.logs:
const webpack = require('webpack');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
module.exports = {
devtool: 'source-map',
entry: [
'bootstrap-loader',
'webpack-hot-middleware/client',
'./src/index',
],
output: {
publicPath: '/dist/',
},
module: {
rules: [{
test: /\.scss$/,
use: [
{ loader: 'style-loader' },
{ loader: 'css-loader', options: { localIdentName: '[path][name]--[local]' } },
{ loader: 'postcss-loader', options: { plugins: function() { return [ require('autoprefixer') ]; }}},
{ loader: 'sass-loader' },
]
}, {
test: /\.css$/,
use: [
'style-loader',
'css-loader',
],
}],
},
devServer: {
hot: true,
contentBase: '/dist/',
publicPath: '/dist/'
},
plugins: [
new webpack.DefinePlugin({
'process.env': { NODE_ENV: '"development"' },
__DEVELOPMENT__: true,
}),
new ExtractTextPlugin({ filename: 'bundle.css' }),
new webpack.HotModuleReplacementPlugin(),
new webpack.NoEmitOnErrorsPlugin(),
],
};
這裏的測試,還是不行,但應該:
常量的WebPack =需要( '的WebPack'); const ExtractTextPlugin = require('extract-text-webpack-plugin');
module.exports = {
devtool: 'source-map',
entry: ['bootstrap-loader/extractStyles'],
output: {
publicPath: 'dist/',
},
module: {
rules: [{
test: /\.scss$/,
use: [
{ loader: 'style-loader' },
{ loader: 'css-loader' },
{ loader: 'postcss-loader', options: { plugins: function() { return [ require('autoprefixer') ]; }}},
{ loader: 'sass-loader' },
]
}, {
test: /\.css$/,
use: [
'style-loader',
'css-loader',
],
}],
},
plugins: [
new webpack.DefinePlugin({
'process.env': { NODE_ENV: '"test"' },
__DEVELOPMENT__: true,
}),
new ExtractTextPlugin({ filename: 'bundle.css' }),
new webpack.optimize.UglifyJsPlugin({ sourceMap: true }),
],
};
初步懷疑Uglify插件,試圖刪除它 - 沒有結果。是什麼賦予了?
什麼樣的'console.log'?從您的應用程序(顯式調用'console.log')還是從構建工具(例如HMR消息)? –
是的,從應用程序,從REDX記錄器等console.log在瀏覽器中可見 –