这是我第一次设置webpack,到目前为止我只是感到困惑。我正在尝试将所有jsx文件收集到各自的文件中,但webpack似乎认为它们不存在...
webpack --display-error-details
我得到的错误看起来像这样:
ERROR in Entry module not found: Error: Cannot resolve 'file' or 'directory' ./static/js/base in /Users/Maude/Projects/School/entry
resolve file
/Users/Maude/Projects/School/entry/static/js/base.js doesn't exist
/Users/Maude/Projects/School/entry/static/js/base.jsx doesn't exist
/Users/Maude/Projects/School/entry/static/js/base is not a file
resolve directory
/Users/Maude/Projects/School/entry/static/js/base/package.json doesn't exist (directory description file)
directory default file index
resolve file index in /Users/Maude/Projects/School/entry/static/js/base
/Users/Maude/Projects/School/entry/static/js/base/index doesn't exist
/Users/Maude/Projects/School/entry/static/js/base/index.jsx doesn't exist
/Users/Maude/Projects/School/entry/static/js/base/index.js doesn't exist
我的静态文件结构如下所示:
static
|- js
|- base
|- base.jsx
|- classes
|- classes.jsx
|- locations.jsx
|- students
|- students.jsx
|- network.jsx
|- teachers
|- teachers.jsx
|- less
最后我的webpack.config.js文件:
module.exports = {
entry: {
base: './static/js/base',
classes: './static/js/classes',
students: './static/js/students',
teachers: './static/js/teachers',
},
output: {
path: './static/bundles',
filename: '[name].js'
},
devServer: {
inline: true,
port: 3333
},
module: {
loaders: [
{
test: /\.js$/,
exclude: '/node_modules/',
loader: 'babel',
query: {
presets: ['es2015', 'react']
}
}
]
},
resolve: {
modulesDirectories: ['/node_modules/'],
extensions: ['', '.js', '.jsx'],
},
}
为什么我明显收到ERROR in Entry module not found: Error: Cannot resolve 'file' or 'directory'
之类的错误?帮助obi-wan!
我的package.json:
{
"name": "--",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "webpack-dev-server"
},
"author": "",
"license": "ISC",
"devDependencies": {
"babel": "^6.5.2",
"babel-core": "^6.11.4",
"babel-loader": "^6.2.4",
"babel-preset-es2015": "^6.9.0",
"babel-preset-react": "^6.11.1",
"bower": "^1.7.9",
"gulp": "^3.9.1",
"gulp-bower": "0.0.13",
"gulp-changed": "^1.3.1",
"gulp-concat": "^2.6.0",
"gulp-cssmin": "^0.1.7",
"gulp-html-replace": "^1.6.1",
"gulp-less": "^3.1.0",
"gulp-load-plugins": "^1.2.4",
"gulp-plumber": "^1.1.0",
"gulp-react": "^3.1.0",
"gulp-rename": "^1.2.2",
"gulp-replace": "^0.5.4",
"gulp-shell": "^0.5.2",
"gulp-uglify": "^1.5.4",
"webpack": "^1.13.1",
"webpack-dev-server": "^1.14.1"
}
}
答案 0 :(得分:2)
我认为你只需要一个条目文件base.jsx,除非你的结构中有一个额外的索引文件。
webpack将抓取导入并从
构建树结构entry: './static/js/base.jsx'
编辑:对于单个入口点,您需要具有以下内容的文件:
React.render(<App />, document.getElementById('app')
从您的packaged.json 看起来它可能是index.js,如果是这样,那么你输入webpack.config.js
entry: './index.js'
然后webpack应该通过跟随import语句来引入整个react应用程序来构建完整的bundle文件。
顺便说一句。没有必要使用.jsx文件扩展名。只需使用.js。这意味着您也不必担心webpack中的扩展字段
btw2。你为什么要混合gulp和webpack?之前从未见过。也许最好去gulp / browserify路线,或者只是坚持使用webpack。