我有以下简单的webpack.config.js文件:
var webpack = require("webpack"); //LINE OF INTEREST
module.exports = {
entry: ["./main.js"],
output: {
path: "./build",
filename: "bundle.js"
},
module: {
loaders: [
{ test: /\.css$/, loader: 'style-loader!css-loader' }
]
},
plugins: [
new webpack.ProvidePlugin({
$: "jquery",
jQuery: "jquery"
})
]
};
当我注释掉定义webpack的顶行时,我收到一个错误,因为我在定义ProvidePlugin时引用了webpack。当我包括第一行时,我得到以下神秘错误:
ERROR in (webpack)/package.json
Module parse failed: /var/www/html/node_modules/webpack/package.json Unexpected token (2:9)
You may need an appropriate loader to handle this file type.
SyntaxError: Unexpected token (2:9)
首先,我不确定为什么我的node_modules文件夹是我的apache根目录。第二,为什么我得到一个解析错误?不是package.json
文件是通过npm安装的吗?怎么会有语法错误呢?
答案 0 :(得分:2)
webpack.config.js
const webpack = require("webpack");
const path = require('path');
module.exports = {
entry: "./main.js",
output: {
path: path.resolve(__dirname, 'build'),
filename: "bundle.js"
},
module: {
rules: [
{
test: /\.css$/,
use: [
{ loader: "style-loader" },
{ loader: "css-loader" }
]
}
]
},
plugins: [
new webpack.ProvidePlugin({
$: "jquery",
jQuery: "jquery"
})
]
};

Working Example 了解更多信息