2016-09-27 47 views
0

我有一個文件調用abc.jsx這樣的WebPack配置不要求工作()中的node.js

var MyTitle = require('./MyTitle') 

but I have to do require('./MyTitle) 

怎麼我運行的WebPack它扔我的錯誤。

ERROR in ./js/MyTitle.jsx 
Module not found: Error: Cannot resolve 'file' or 'directory' ./MyTitle in /Users/username/Documents/intro-to-react/js 
@ ./js/MyTitle.jsx 5:14-34 

回答

0

你應該設置webpack配置來使用babel-loader來解析jsx文件。模塊加載器中的以下行test: /\.js?$/,告訴webpack解析.js.jsx文件類型。

var webpack = require('webpack'); 
var path = require('path'); 

module.exports = { 
    context: path.join(__dirname, "src"), 
    devtool: "inline-sourcemap", 
    entry: "./js/client.js", 
    module: { 
    loaders: [ 
     { 
     test: /\.js?$/, 
     exclude: /(node_modules|bower_components)/, 
     loader: 'babel-loader', 
     query: { 
      presets: ['react', 'es2015', 'stage-0'], 
      plugins: ['react-html-attrs', 'transform-decorators-legacy'], 
     } 
     } 
    ] 
    }, 
    output: { 
    path: __dirname + "/src/", 
    filename: "client.min.js" 
    } 
};