我的webpack-dev-server工作很慢。我有以下webpack.config.js文件:
'use strict';
var path = require('path');
var webpack = require('webpack');
var glob = require("glob");
module.exports = {
entry: {
wit: [babel-polyfill',
'./index.js',
'./src/shared/styles.less']
},
output: {
path: path.resolve(__dirname, 'dist/'),
//publicPath: '/',
filename: 'bundle.[name].js'
},
module: {
rules: [
{
test: /(\.js[\S]{0,1})$/i,
exclude: /node_modules/,
loaders: ['babel-loader?presets[]=env&presets[]=react&presets[]=stage-0&presets[]=stage-2']
},
{
test: /\.(htm|html|xhtml|hbs|handlebars|php|ejs)$/i,
exclude: /node_modules/,
loader: "file?name=[name].[ext]",
},
{
test: /\.css$/i,
exclude: [/node_modules/],
loader: 'style-loader!css-loader'
},
{
test: /\.less$/i,
exclude: /node_modules/,
use: [{
loader: "style-loader" // creates style nodes from JS strings
}, {
loader: "css-loader" // translates CSS into CommonJS
}, {
loader: "less-loader" // compiles Less to CSS
}]
},
// this rule handles images
{ test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/, loader: "url-loader?limit=10000&mimetype=application/font-woff" },
{ test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/, loader: "file-loader" },
{
test: /\.(jpe?g|png|gif)$/i,
exclude: /node_modules/,
use: [
'url-loader?limit=10000',
'img-loader',
'file-loader?name=[name].[ext]?[hash]'
]
},
{
test: /\.json$/,
exclude: /node_modules/,
loader: "json-loader"
},
// the following 3 rules handle font extraction
{
test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/,
loader: 'url-loader?limit=10000&mimetype=application/font-woff'
},
{
test: /\.(ttf|eot)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
loader: 'file-loader'
},
{
test: /\.otf(\?.*)?$/,
use: 'file-loader?name=/fonts/[name]. [ext]&mimetype=application/font-otf'
}
]
},
plugins : [
new webpack.ProvidePlugin({
"React": "react", 'react-dom': 'ReactDOM'
})
],
resolve: {
extensions: ['.js', '.es6', '.jsx', 'less','config','variables','overrides']
},
performance: {
hints: false
},
watch: false,
target: 'web',
devServer: {
stats: {
colors: true,
chunks: false,
hash: false,
version: false,
timings: false,
assets: false,
reasons: false,
children: false,
source: false,
errors: false,
errorDetails: false,
warnings: false,
noInfo: true
}
},
externals: [
{pg: true}
],
node: {
fs: 'empty'
}
};
答案 0 :(得分:0)
我找到了一个解决方案来删除以下内容: 而不是
entry: {
pit: [babel-polyfill',
'./index.js',
'./src/shared/styles.less']
},
你需要删除重负荷的babel-polyfill'。所以你有这个部分:
entry: {
pit: [
'./index.js',
'./src/shared/styles.less']
},
您需要删除重度可执行规则:
{
test: /\.(htm|html|xhtml|hbs|handlebars|php|ejs)$/i,
exclude: /node_modules/,
loader: "file?name=[name].[ext]",
},
因此,您将拥有非常快速的webpack-dev-server脚本:
'use strict';
var path = require('path');
var webpack = require('webpack');
var glob = require("glob");
module.exports = {
entry: {
pit: [
'./index.js',
'./src/shared/styles.less']
},
output: {
path: path.resolve(__dirname, 'dist/'),
//publicPath: '/',
filename: 'bundle.[name].js'
},
module: {
rules: [
{
test: /(\.js[\S]{0,1})$/i,
exclude: /node_modules/,
loaders: ['babel-loader?presets[]=env&presets[]=react&presets[]=stage-0&presets[]=stage-2']
},
{
test: /\.css$/i,
exclude: [/node_modules/],
loader: 'style-loader!css-loader'
},
{
test: /\.less$/i,
exclude: /node_modules/,
use: [{
loader: "style-loader" // creates style nodes from JS strings
}, {
loader: "css-loader" // translates CSS into CommonJS
}, {
loader: "less-loader" // compiles Less to CSS
}]
},
// this rule handles images
{ test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/, loader: "url-loader?limit=10000&mimetype=application/font-woff" },
{ test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/, loader: "file-loader" },
{
test: /\.(jpe?g|png|gif)$/i,
exclude: /node_modules/,
use: [
'url-loader?limit=10000',
'img-loader',
'file-loader?name=[name].[ext]?[hash]'
]
},
{
test: /\.json$/,
exclude: /node_modules/,
loader: "json-loader"
},
// the following 3 rules handle font extraction
{
test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/,
loader: 'url-loader?limit=10000&mimetype=application/font-woff'
},
{
test: /\.(ttf|eot)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
loader: 'file-loader'
},
{
test: /\.otf(\?.*)?$/,
use: 'file-loader?name=/fonts/[name]. [ext]&mimetype=application/font-otf'
}
]
},
plugins : [
new webpack.ProvidePlugin({
"React": "react", 'react-dom': 'ReactDOM'
})
],
resolve: {
extensions: ['.js', '.es6', '.jsx', 'less','config','variables','overrides']
},
performance: {
hints: false
},
watch: false,
target: 'web',
devServer: {
stats: {
colors: true,
chunks: false,
hash: false,
version: false,
timings: false,
assets: false,
reasons: false,
children: false,
source: false,
errors: false,
errorDetails: false,
warnings: false,
noInfo: true
}
},
externals: [
{pg: true}
],
node: {
fs: 'empty'
}
};