Vis*_*tel 4 webpack react-jsx babeljs
我真的很感激这方面的帮助:我无法使用webpack构建,我得到一个简短的错误列表,从以下开始:
Module not found: Error: Cannot resolve module 'react' in ../client/front_desk.jsx
Run Code Online (Sandbox Code Playgroud)
最后得到一个长列表,如下所示:
Module not found: Error: Cannot resolve 'file' or 'directory' ../node_modules/process/browser.js
Run Code Online (Sandbox Code Playgroud)
这是我的webpack.config.js:
const webpack = require('webpack');
const commonsPlugin = new webpack.optimize.CommonsChunkPlugin('common.js');
module.exports = {
entry: {
front_desk: './front/client/front_desk',
},
resolve: {
extensions: ['.js', '.jsx'],
},
output: {
path: 'front/public/js',
filename: '[name].js', // Template based on keys in entry above
},
module: {
loaders: [
{
test: /\.(jsx|js)?$/,
loader: 'babel',
query: {
presets: ['es2015', 'react'],
},
},
],
},
plugins: [commonsPlugin],
};
Run Code Online (Sandbox Code Playgroud)
而我的.babelrc:
{
"plugins": ["syntax-jsx"],
"presets": ["react", "es2015"],
}
Run Code Online (Sandbox Code Playgroud)
我的依赖项列表在package.json中:
"dependencies": {
"aguid": "*",
"babel-plugin-syntax-jsx": "*",
"babel-preset-es2015": "*",
"babel-preset-react": "*",
"babel-register": "*",
"bcrypt": "*",
"eslint": "*",
"eslint-config-airbnb": "^8.0.0",
"eslint-plugin-import": "^1.6.1",
"eslint-plugin-jsx-a11y": "^1.0.4",
"eslint-plugin-react": "^5.0.1",
"hapi": "*",
"hapi-react-views": "^7.0.0",
"inert": "*",
"isomorphic-fetch": "*",
"mailparser": "*",
"mandrill-api": "*",
"mongodb": "*",
"nodemon": "*",
"react": "^15.0.2",
"react-dom": "^15.0.2",
"react-redux": "*",
"redux": "*",
"redux-thunk": "*",
"twilio": "*",
"vision": "*",
"webpack-dev-server": "^1.14.1"
},
"devDependencies": {
"babel-core": "*",
"babel-loader": "*",
"faucet": "*",
"jsx-loader": "^0.13.2",
"nodemon": "*",
"tape": "*",
"webpack": "*"
}
Run Code Online (Sandbox Code Playgroud)
Vis*_*tel 18
弄清楚了!我首先使用--display-error-details运行webpack,在我看来应该一直默认启用.webpack --progress --color --watch --display-error-details.
这告诉我,webpack遇到这么困难的原因是因为我告诉它要寻找的扩展有问题:
resolve: {
extensions: ['.js', '.jsx'],
},
Run Code Online (Sandbox Code Playgroud)
会寻找react.js.js和react.js.jsx而不仅仅是react.js.所以,我必须将其更新为:
resolve: {
extensions: ['', '.js', '.jsx'],
},
Run Code Online (Sandbox Code Playgroud)
哪个修好了!=)
| 归档时间: |
|
| 查看次数: |
10367 次 |
| 最近记录: |