我将按照官方Webpack入门指南进行翻译,但在使用配置部分遇到了错误。它要求创建一个webpack.config.js文件,并添加以下内容:
const path = require('path');
module.exports = {
entry: './src/index.js',
output: {
filename: 'main.js',
path: path.resolve(__dirname, 'dist')
}
};
我随后运行了以下命令:
npx webpack --config webpack.config.js
我得到的错误是:Cannot find module '/Users/Documents/Web_Development/tone/webpack.config.js'
指南似乎没有提供任何可能出错的想法。此外,我的代码编辑器告诉我const path = require('path');
有一个错误,说“预期为JSON对象、数组或文字;”我的目录结构:
webpack.config.json
package.json.lock
package.json
node_modules/
dist/
index.html
main.js
src/
index.js
package.json:
{
"name": "tone",
"version": "1.0.0",
"description": "",
"private": true,
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"babel-core": "^6.26.3",
"webpack": "^4.29.3",
"webpack-cli": "^3.2.3"
},
"dependencies": {
"lodash": "^4.17.11"
}
}