Webpack 试图捆绑自己?
Webpack trying to bundle itself?
我在这里看到了一个相当基本的 webpack 配置。
module.exports = {
entry: "./app/app.js",
output: {
filename: "public/bundle.js"
},
module: {
loaders: [
{
exclude: /node_modules/,
include: /app/,
loader: 'babel-loader'
}
]
},
// Without this the console says all errors are coming from just coming from bundle.js
devtool: "eval-source-map"
};
但是我正在尝试将 webpack 导出 jQuery 作为全局(因为我正在使用的一些包寻找 jQuery 全局)。
文档说明 here 你可以这样做:
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery'
})
然而,要将该块添加到我的配置中,我必须在上面 webpack.config.js
中包含 webpack。当我添加 const webpack = require("webpack");
时,webpack 似乎开始尝试捆绑 webpack。向控制台输出大量错误。为什么会这样,webpack 不应该尝试在 webpack.config.js
中捆绑依赖项吗?
编辑:
似乎 webpack 一直在捆绑我的配置文件,尽管在我将 webpack 包含在文件中之前这从来都不是问题。下面显示的输出显示了与上述配置捆绑在一起的配置文件。
Hash: cba679dd5938953cc8b8
Version: webpack 3.11.0
Time: 1576ms
Asset Size Chunks Chunk Names
public/bundle.js 4.37 MB 0 [emitted] [big] main
[1] ./app/modules/<filename>.js 1.77 kB {0} [built]
[3] multi ./app/app.js ./webpack.config.js 40 bytes {0} [built]
[4] ./app/app.js 174 bytes {0} [built]
[5] ./app/js/<filename>.js 2.49 kB {0} [built]
[6] ./app/js/<filename>.js 4.96 kB {0} [built]
[13] ./webpack.config.js 664 bytes {0} [built]
+ 9 hidden modules
上面标记为 [3]
的行是我的问题,尽管我的配置似乎根本没有告诉 webpack 这样做。
这里的问题是我是 运行 带有命令 npx webpack webpack.config.js
的 webpack。正确的命令只是 npx webpack
,添加 webpack.config.js
将其添加为另一个入口点。
我在这里看到了一个相当基本的 webpack 配置。
module.exports = {
entry: "./app/app.js",
output: {
filename: "public/bundle.js"
},
module: {
loaders: [
{
exclude: /node_modules/,
include: /app/,
loader: 'babel-loader'
}
]
},
// Without this the console says all errors are coming from just coming from bundle.js
devtool: "eval-source-map"
};
但是我正在尝试将 webpack 导出 jQuery 作为全局(因为我正在使用的一些包寻找 jQuery 全局)。
文档说明 here 你可以这样做:
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery'
})
然而,要将该块添加到我的配置中,我必须在上面 webpack.config.js
中包含 webpack。当我添加 const webpack = require("webpack");
时,webpack 似乎开始尝试捆绑 webpack。向控制台输出大量错误。为什么会这样,webpack 不应该尝试在 webpack.config.js
中捆绑依赖项吗?
编辑:
似乎 webpack 一直在捆绑我的配置文件,尽管在我将 webpack 包含在文件中之前这从来都不是问题。下面显示的输出显示了与上述配置捆绑在一起的配置文件。
Hash: cba679dd5938953cc8b8
Version: webpack 3.11.0
Time: 1576ms
Asset Size Chunks Chunk Names
public/bundle.js 4.37 MB 0 [emitted] [big] main
[1] ./app/modules/<filename>.js 1.77 kB {0} [built]
[3] multi ./app/app.js ./webpack.config.js 40 bytes {0} [built]
[4] ./app/app.js 174 bytes {0} [built]
[5] ./app/js/<filename>.js 2.49 kB {0} [built]
[6] ./app/js/<filename>.js 4.96 kB {0} [built]
[13] ./webpack.config.js 664 bytes {0} [built]
+ 9 hidden modules
上面标记为 [3]
的行是我的问题,尽管我的配置似乎根本没有告诉 webpack 这样做。
这里的问题是我是 运行 带有命令 npx webpack webpack.config.js
的 webpack。正确的命令只是 npx webpack
,添加 webpack.config.js
将其添加为另一个入口点。