node.js - bundle.js 404 (Not Found) -


i'm trying bundle react app using webpack client-side rendering , including bundle.js in tag. however, whenever run app keep getting 404 (not found) bundle.js. here webpack.config.js:

webpack.config.js

const path = require('path');  const config = {   entry: ['babel-polyfill', './views/index.jsx'],   output: {     path: path.resolve(__dirname, 'public'),     filename: 'bundle.js',     publicpath: '/'   },   module: {     rules: [       { test: /\.(jsx|js)$/, exclude: /node_modules/ , use: 'babel-loader' }     ]   } };  module.exports = config; 

./views/index.jsx points main template file looks this:

index.jsx

import react 'react'; import layout './layout.jsx'; import cube './components/cube/cube.jsx';  class index extends react.component {   render() {     return (         <layout title={this.props.title}>             <cube />         </layout>     );   } }  export default index; 

where layout.jsx i'm including <script src="/public/bundle.js">:

layout.jsx

import react 'react';  class layout extends react.component {   render() {     return (       <html>         <head>           <title>{this.props.title}</title>           <script type="text/javascript" src="/public/bundle.js"></script>         </head>         <body>           {this.props.children}         </body>       </html>     );   } }  export default layout; 

can me understand why isn't working? full project if helps: https://github.com/markscode/personalwebsite

i think might have me using server-side rendering express-react-views package wrong?

thanks!

it doesn't telling express serve public folder @ all. you'll need explicitly let express know public folder should serve static files, so:

app.use(express.static('public')) 

docs here: https://expressjs.com/en/starter/static-files.html


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -