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

add major features from webpack-dev-server #55

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

pkit
Copy link

@pkit pkit commented Feb 21, 2020

  • compress
  • proxy
  • before
  • after
  • historyApiFallback (object format)
  • serveIndex
  • headers

The end goal is to make sure it can run react-scripts config (almost) unmodified

- compress
- proxy
- before
- after
- historyApiFallback (object format)
- serveIndex
- headers
@thgh
Copy link
Owner

thgh commented Feb 26, 2020

This looks promising, but I don't have the time to review this completely so I hope somebody else can review.

I released the PR as rollup-plugin-serve@2.0.0-beta.0

options.port = options.port || 10001
options.headers = options.headers || {}
options.https = options.https || false
options.openPage = options.openPage || ''
options.compress = !!options.compress
options.serveIndex = options.serveIndex || (options.serveIndex === undefined)
Copy link
Owner

Choose a reason for hiding this comment

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

These new options should be documented in README.md

Copy link
Author

Choose a reason for hiding this comment

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

Yep, obviously. And some tests added.

Comment on lines +36 to +43
"compression": "^1.7.4",
"connect-history-api-fallback": "^1.6.0",
"express": "^4.17.1",
"http-proxy-middleware": "^1.0.0",
"killable": "^1.0.1",
"mime": ">=2.0.3",
"opener": "1"
"opener": "1",
"serve-index": "^1.9.1"
Copy link
Owner

Choose a reason for hiding this comment

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

What do you think about moving all of these to devDependencies and bundling them in the plugin with rollup?

Copy link
Author

Choose a reason for hiding this comment

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

Seems ok.

}
}

const runnableFeatures = []
Copy link
Owner

Choose a reason for hiding this comment

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

How much of this code is copied from webpack-dev-server?

Copy link
Author

Choose a reason for hiding this comment

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

Some of the complex features. Like proxy and feature order.
I don't see how to get feature/bug parity without it.
The license is MIT though, so probably needs a better embedding of the source with the correct attribution.

@prantlf
Copy link

prantlf commented Dec 7, 2022

A happy user of rollup-plugin-serve@2.0.0-beta.0 here. I'm especially happy about the directory indexes, because I have several development pages in my project and I like to navigate to them in the browser. My configuration:

  serve({
    open: false,
    port: 8080,
+   contentBase: __dirname, // I have rollup config in the project root
+   serveIndex: true,
  })

If I don't add the contentBase, it'll fail:

[!] TypeError: root path required
TypeError: root path required
    at Function.serveStatic [as static] (/Users/ferdipr/Sources/gitlab/ot-web-components/node_modules/serve-static/index.js:40:11)
    at /Users/ferdipr/Sources/gitlab/ot-web-components/node_modules/rollup-plugin-serve/dist/index.cjs.js:189:58
    at Array.forEach (<anonymous>)
    at Object.contentBaseFiles (/Users/ferdipr/Sources/gitlab/ot-web-components/node_modules/rollup-plugin-serve/dist/index.cjs.js:188:29)
    at /Users/ferdipr/Sources/gitlab/ot-web-components/node_modules/rollup-plugin-serve/dist/index.cjs.js:272:22
    at Array.forEach (<anonymous>)
    at Object.serve [as default] (/Users/ferdipr/Sources/gitlab/ot-web-components/node_modules/rollup-plugin-serve/dist/index.cjs.js:271:42)
    at Object.<anonymous> (/Users/ferdipr/Sources/gitlab/ot-web-components/rollup.config.js:81:46)
    at Module._compile (node:internal/modules/cjs/loader:1155:14)
    at Object.require.extensions.<computed> [as .js] (/Users/ferdipr/Sources/gitlab/ot-web-components/node_modules/rollup/dist/shared/loadConfigFile.js:621:20)

The default contentBase: '' worked earlier to serve the content of the current directory. You might want to send process.cwd() to the serve-static, so that it wouldn't fail with the default configuration right away.

return next()
}

serveIndex(item)(req, res, next)
Copy link

@prantlf prantlf Dec 12, 2022

Choose a reason for hiding this comment

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

The interface of serveIndex is serveIndex(path, options). There're some important options there like icons: true, for which my colleague is mourning now, when migrating from webpack to rollup ;-) How about passing the options for serve-index down?

This is possible now, using the defaults of serve-index:

serve({
  open: false,
  port: 8080,
  contentBase: __dirname,
  serveIndex: true
})

How about letting us customise the options of serve-index like this:

serve({
  open: false,
  port: 8080,
  contentBase: __dirname,
  serveIndex: { icons: true }
})

It'd mean this code change:

- serveIndex(item)(req, res, next)
+ serveIndex(item, options.serveIndex)(req, res, next)

@prantlf
Copy link

prantlf commented Jan 9, 2023

This feature was included in 2.0.0-beta.0, but it didn't make it to 2.0.0. Are there any plans to include it in an upcoming version? Thank you!

@prantlf
Copy link

prantlf commented Mar 30, 2023

2.0.2 was released without this feature. Are you going to accept ii? Or do you want to close this PR and wait for a different one?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants