Skip to content

add major features from webpack-dev-server#55

Open
pkit wants to merge 1 commit intothgh:masterfrom
pkit:wds_features1
Open

add major features from webpack-dev-server#55
pkit wants to merge 1 commit intothgh:masterfrom
pkit:wds_features1

Conversation

@pkit
Copy link
Copy Markdown

@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
Copy Markdown
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.https = options.https || false
options.openPage = options.openPage || ''
options.compress = !!options.compress
options.serveIndex = options.serveIndex || (options.serveIndex === undefined)
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Author

Choose a reason for hiding this comment

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

Seems ok.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I think that keeping the dependencies external is better.

  • All existing dependencies are external.
  • The size of this package will be smaller.
  • People will be able to override the versions of the dependencies in this package.json with other versions, when they depend on this package.

}
}

const runnableFeatures = []
Copy link
Copy Markdown
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
Copy Markdown
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.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The construct with features and runnableFeatures could be dropped. I think that a simple chain of conditions if (options.xxx) is more readable. Unless you want to encapsulate each option processing to a function.

@prantlf
Copy link
Copy Markdown

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
Copy Markdown

@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
Copy Markdown

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
Copy Markdown

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?

@prantlf
Copy link
Copy Markdown

prantlf commented Jan 3, 2026

I rebased this PR onto the latest master and opened #106 with minor changes.

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.

3 participants