2017-06-26 26 views
0

嘿,我正在設置我的開發服務器,我希望webpack可以搜索每個.js文件,並使用babel將它們傳輸。按照目前的設置,我的bundle.js只包含我的入口點的內容,但不包括項目目錄中的其他js文件。有小費嗎 ?只包含入口點js文件但僅包含其他文件的網頁包

這是我的WebPack配置

module.exports = { 

    entry: './app/src/index.js', 
    output:{ 
     path: __dirname, 
     publicPath:'/', 
     filename: 'bundle.js' 
    }, 
    devServer:{ 
     inline: true, 
     contentBase:'./', 
     port: 61116 

    }, 
    module: { 
     loaders: [ 
      { 
       test: /\.js$/, 
       exclude:/(node_modules)/, 
       loader: 'babel-loader', 
       query: { 
        presets: ["es2015", "react", "stage-1"] 
       } 
      }, 
      { 
       test: /\.css$/, 
       loader:"style-loader!css-loader" 
      }, 
      { 
       test: /\.html$/, 
       loader:"html-loader" 

      } 
     ] 
    } 
} 

,這是我的文件夾結構

enter image description here

切入點index.js

import React from 'react' ; 
import ReactDOM from 'react-dom'; 

console.log("This ran"); 
const App =() =>{ 
    return (<p>This is a new app</p>); 
} 


ReactDOM.render(<App />, document.querySelector(".react-container")); 

任何想法,我錯了嗎?

+0

你可以發佈你的入口點「index.js」文件的內容嗎? – Dennis

+0

添加了index.js,這些更改確實出現在捆綁包.js上,但對其他.js文件的更改沒有添加到bundle.js中 – Gregborrelly

+1

您的_index.js_文件實際上並未使用任何React/Redux代碼。嘗試在_components_ dir中定義一個'TestComponent.jsx',然後導入入口點_index.js_文件並使用它。 'const app =()=>(

This is a new app

);' – IsenrichO

回答

1

由於IsenrichO暗示在評論中,您似乎沒有在組件文件夾中包含「index.js」。任何不是由入口點首先導入的文件,或入口點導入的任何文件等都不會被轉發。

嘗試import IndexComponent from "./components/index";,或任何您的索引組件類的名稱。

+0

這是問題,因爲我沒有將它們導入入口點。他們被忽略了。 – Gregborrelly