Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added webpack dynamic import routes to the router. #742

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@ export default class Server {
const p = join(__dirname, '..', 'client', ...(params.path || []))
await serveStatic(req, res, p)
})

this.router.get('/_webpack/:number', async (req, res, params) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In what case?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also am not sure exactly when this path is used, but some files, like patch files of HMR, are served from it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I read #728, is this intentional ? Anyway it would be better to use a same logic to serve these files on dev and production IMO.

Copy link
Contributor

@arunoda arunoda Jan 11, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think here _webpack is the path we exposed as publicPath in the config.

I think in the dev mode, this is implemented by the webpack dev server itself. We only need to do this on production.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@arunoda makes sense

Copy link
Contributor

@arunoda arunoda Jan 12, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, shall we add this route only in the production mode? So we are sure, we don't interfere with the webpack dev server.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So with an if ( dev ) this should be ok @nkzawa ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any thoughts?

if (isNaN(params.number)) throw new Error('Webpack dynamic imports should be numbered')
Copy link
Contributor

@nkzawa nkzawa Jan 12, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should respond with appropriate status code (404) ?

const p = join(this.dir, '.next', params.number)
await serveStaticWithGzip(req, res, p)
})

this.router.get('/static/:path+', async (req, res, params) => {
const p = join(this.dir, 'static', ...(params.path || []))
await serveStatic(req, res, p)
Expand Down