为什么即使我排除了node_modules,Webpack命令也要花这么长时间



我一直在尝试从ReactJS教程中学习React和Webpack。我的问题是,当我在所有文件的顶级目录中运行webpack时,通常需要大约62392ms。但是,在教程中,他采用了1394ms。我读过让排除应该有助于增加性能时间,但我已经排除了节点模块。我试着将我的loader切换到仅babel,这使我的webpack时间降到了113183ms。但这似乎仍然非常慢,尤其是当它只传输一个文件时(client.js)。有人知道为什么运行webpack命令如此慢吗,因为大多数其他stackerflow答案似乎都指向包含/排除路径/目录,而我已经这样做了吗?

我的文件结构如下:

node_modules
src
->  js
->->    client.js
->  client.min.js
->  index.html
.gitignore
package.json
webpack.config.js

我的webpack.config.js看起来像:

var debug = process.env.NODE_ENV !== "production";
var webpack = require('webpack');
var path = require('path');
module.exports = {
context: __dirname + "/src",
devtool: debug ? "inline-sourcemap" : null,
entry: "./js/client.js",
module: {
loaders: [
{
target: 'node',
test: /.jsx?$/,
//include: [path.resolve(__dirname, "./src")],
exclude: /node_modules/,
loader: 'babel-loader',
query: {
presets: ['react', 'es2015', 'stage-0'],
plugins: ['react-html-attrs', 'transform-class-properties', 'transform-decorators-legacy'],
}
}
]
},
output: {
path: __dirname + "/src/",
filename: "client.min.js"
},
plugins: debug ? [] : [
new webpack.optimize.DedupePlugin(),
new webpack.optimize.OccurenceOrderPlugin(),
new webpack.optimize.UglifyJsPlugin({ mangle: false, sourcemap: false }),
],
};

我的package.json看起来像:

{
"name": "module-loaders",
"version": "1.0.0",
"description": "Learning React and Webpack through LearnCode.academy",
"main": "index.js",
"scripts": {
"test": "echo "Error: no test specified" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/dustinchang/React_Learning_LearnCode.Academy.git"
},
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/dustinchang/React_Learning_LearnCode.Academy/issues"
},
"homepage": "https://github.com/dustinchang/React_Learning_LearnCode.Academy#readme",
"dependencies": {
"babel-core": "^6.9.1",
"babel-loader": "^6.2.0",
"babel-plugin-add-module-exports": "^0.1.2",
"babel-plugin-react-html-attrs": "^2.0.0",
"babel-plugin-transform-class-properties": "^6.3.13",
"babel-plugin-transform-decorators-legacy": "^1.3.4",
"babel-preset-es2015": "^6.3.13",
"babel-preset-react": "^6.3.13",
"babel-preset-stage-0": "^6.3.13",
"react": "^0.14.6",
"react-dom": "^0.14.6",
"webpack": "^1.13.1",
"webpack-dev-server": "^1.14.1"
}
}

我非常感谢你的建议。

在Windows上,您可以激活缓存目录babel选项](https://github.com/babel/babel-loader#options)。它在重新加载时为我节省了很多时间。

最新更新