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

V1 #32

Merged
merged 6 commits into from Jan 11, 2019
Merged

V1 #32

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 11 additions & 1 deletion CHANGELOG.md
Expand Up @@ -2,6 +2,13 @@

All notable changes to `rollup-plugin-serve` will be documented in this file.

## [1.0.0] - 2019-01-11
### Fixed
- Update `ongenerate` to `generateBundle`

### Removed
- Remove built-in `favicon.ico` #20

## [0.6.1] - 2018-12-23
### Added
- Add support for `rollup --watch` (Release http server on rollup reload)
Expand Down Expand Up @@ -50,7 +57,10 @@ All notable changes to `rollup-plugin-serve` will be documented in this file.
### Added
- Initial version

[Unreleased]: https://github.com/thgh/rollup-plugin-serve/compare/v0.1.0...HEAD
[Unreleased]: https://github.com/thgh/rollup-plugin-serve/compare/v1.0.0...HEAD
[1.0.0]: https://github.com/thgh/rollup-plugin-serve/compare/v0.6.1...v1.0.0
[0.6.1]: https://github.com/thgh/rollup-plugin-serve/compare/v0.5.0...v0.6.1
[0.5.0]: https://github.com/thgh/rollup-plugin-serve/compare/v0.4.2...v0.5.0
[0.4.2]: https://github.com/thgh/rollup-plugin-serve/compare/v0.4.1...v0.4.2
[0.4.1]: https://github.com/thgh/rollup-plugin-serve/compare/v0.4.0...v0.4.1
[0.4.0]: https://github.com/thgh/rollup-plugin-serve/compare/v0.3.0...v0.4.0
Expand Down
6 changes: 5 additions & 1 deletion README.md
Expand Up @@ -18,7 +18,11 @@

## Installation
```
# Rollup v0.60+ and v1+
npm install --save-dev rollup-plugin-serve

# Rollup v0.59 and below
npm install --save-dev rollup-plugin-serve@0
```

## Usage
Expand All @@ -27,7 +31,7 @@ npm install --save-dev rollup-plugin-serve
import serve from 'rollup-plugin-serve'

export default {
input: 'entry.js',
input: 'src/main.js',
output: {
file: 'dist/bundle.js',
format: ...
Expand Down
Binary file removed dist/favicon.ico
Binary file not shown.
20 changes: 11 additions & 9 deletions package.json
@@ -1,15 +1,16 @@
{
"name": "rollup-plugin-serve",
"version": "0.6.1",
"version": "1.0.0",
"description": "Serve your rolled up bundle",
"main": "dist/index.cjs.js",
"module": "dist/index.es.js",
"jsnext:main": "dist/index.es.js",
"scripts": {
"build": "rollup -c -f cjs -o dist/index.cjs.js && rollup -c -f es -o dist/index.es.js",
"dev": "rollup -cw -f cjs -o dist/index.cjs.js",
"lint": "standard rollup.config.js src/**",
"prepare": "npm run build"
"build": "rollup -c",
"dev": "rollup -cw",
"lint": "standard --fix rollup.config.js src/**",
"prepare": "yarn lint && yarn build",
"test": "cd test && rollup -c || cd .."
},
"keywords": [
"rollup",
Expand All @@ -32,11 +33,12 @@
"dist"
],
"dependencies": {
"mime": "^1.3.6",
"opener": "^1.4.3"
"mime": "2",
"opener": "1"
},
"devDependencies": {
"rollup": "^0.48.2",
"rollup-plugin-buble": "^0.15.0"
"rollup": "1",
"rollup-plugin-buble": "^0.15.0",
"standard": "12"
}
}
7 changes: 4 additions & 3 deletions rollup.config.js
Expand Up @@ -2,10 +2,11 @@ import buble from 'rollup-plugin-buble'

export default {
input: 'src/index.js',
output: 'dist/index.cjs.js',
plugins: [
buble()
output: [
{ file: 'dist/index.cjs.js', format: 'cjs' },
{ file: 'dist/index.es.js', format: 'esm' }
],
plugins: [buble()],
onwarn ({ code, message }) {
if (code !== 'UNRESOLVED_IMPORT') {
console.warn(message)
Expand Down
19 changes: 4 additions & 15 deletions src/index.js
Expand Up @@ -36,22 +36,11 @@ export default function serve (options = { contentBase: '' }) {
response.writeHead(500)
response.end('500 Internal Server Error' +
'\n\n' + filePath +
'\n\n' + Object.keys(error).map(function (k) {
return error[k]
}).join('\n') +
'\n\n' + Object.values(error).join('\n') +
'\n\n(rollup-plugin-serve)', 'utf-8')
return
}
if (request.url === '/favicon.ico') {
filePath = resolve(__dirname, '../dist/favicon.ico')
readFile(filePath, function (error, content) {
if (error) {
notFound(response, filePath)
} else {
found(response, filePath, content)
}
})
} else if (options.historyApiFallback) {
if (options.historyApiFallback) {
var fallbackPath = typeof options.historyApiFallback === 'string' ? options.historyApiFallback : '/index.html'
readFileFromContentBase(options.contentBase, fallbackPath, function (error, content, filePath) {
if (error) {
Expand Down Expand Up @@ -84,7 +73,7 @@ export default function serve (options = { contentBase: '' }) {

return {
name: 'serve',
ongenerate () {
generateBundle () {
if (!running) {
running = true

Expand Down Expand Up @@ -130,7 +119,7 @@ function notFound (response, filePath) {
}

function found (response, filePath, content) {
response.writeHead(200, { 'Content-Type': mime.lookup(filePath) })
response.writeHead(200, { 'Content-Type': mime.getType(filePath) })
response.end(content, 'utf-8')
}

Expand Down
3 changes: 2 additions & 1 deletion test/base1/index.html
@@ -1,2 +1,3 @@
test/base1/index.html
<!doctype html>
File: /base1/index.html
<script src="dest.js"></script>
3 changes: 2 additions & 1 deletion test/base1/test1.html
@@ -1,2 +1,3 @@
test/base1/test1.html
<!doctype html>
File: /base1/test1.html
<script src="dest.js"></script>
3 changes: 2 additions & 1 deletion test/base2/index.html
@@ -1,2 +1,3 @@
test/base2/index.html
<!doctype html>
File: /base2/index.html
<script src="dest.js"></script>
3 changes: 2 additions & 1 deletion test/base2/test2.html
@@ -1,2 +1,3 @@
test/base2/test2.html
<!doctype html>
File: /base2/test2.html
<script src="dest.js"></script>
2 changes: 1 addition & 1 deletion test/entry.js
@@ -1,4 +1,4 @@
import lib from './lib.js'

window.onload = () => document.body.innerHTML += '<br>' + window.location.pathname
window.onload = () => document.body.innerHTML += '<br>Path: ' + window.location.pathname
+ '<br>' + lib
2 changes: 2 additions & 0 deletions test/fallback.html
@@ -0,0 +1,2 @@
<!doctype html>
Fallback
77 changes: 53 additions & 24 deletions test/frames.html
@@ -1,28 +1,57 @@
<!doctype html>
<style type="text/css">
*{ vertical-align: top; }
* {
vertical-align: top;
}
iframe {
height: 80px;
height: 70px;
width: 200px;
border: 1px solid #ccc;
}
th {
padding-top: 1rem;
letter-spacing: 1px;
}
</style>
<div>
<iframe src="."></iframe>
</div>
<div>
<iframe src="/"></iframe>
</div>
<div>
<iframe src="./base1"></iframe>
<iframe src="./base1/"></iframe>
</div>
<div>
<iframe src="./base2"></iframe>
<iframe src="./base2/"></iframe>
</div>
<div>
<iframe src="./test1.html"></iframe>
<iframe src="./base1/test1.html"></iframe>
</div>
<div>
<iframe src="./test2.html"></iframe>
<iframe src="./base2/test2.html"></iframe>
</div>
<table>
<tr>
<th></th>
<th>No trailing slash</th>
<th>Trailing slash</th>
<th>error.html</th>
</tr>
<tr>
<td>.</td>
<td><iframe src="."></iframe></td>
<td><iframe src="./"></iframe></td>
<td><iframe src="error.html"></iframe></td>
</tr>
<tr>
<td>./base1</td>
<td><iframe src="./base1"></iframe></td>
<td><iframe src="./base1/"></iframe></td>
</tr>
<tr>
<td>./base2</td>
<td><iframe src="./base2"></iframe></td>
<td><iframe src="./base2/"></iframe></td>
</tr>
<tr>
<th></th>
<th>./</th>
<th>./base1/</th>
<th>./base2/</th>
</tr>
<tr>
<td>test1.html</td>
<td><iframe src="./test1.html"></iframe></td>
<td><iframe src="./base1/test1.html"></iframe></td>
<td><iframe src="./base2/test1.html"></iframe></td>
</tr>
<tr>
<td>test2.html</td>
<td><iframe src="./test2.html"></iframe></td>
<td><iframe src="./base1/test2.html"></iframe></td>
<td><iframe src="./base2/test2.html"></iframe></td>
</tr>
</table>
3 changes: 2 additions & 1 deletion test/index.html
@@ -1,2 +1,3 @@
test/index.html
<!doctype html>
File: /index.html
<script src="dest.js"></script>
13 changes: 9 additions & 4 deletions test/rollup.config.js
@@ -1,11 +1,16 @@
import serve from 'rollup-plugin-serve'
import serve from '..'

export default {
entry: 'entry.js',
dest: 'dest.js',
input: 'entry.js',
output: {
file: 'dest.js',
format: 'cjs'
},
plugins: [
serve({
historyApiFallback: true,
open: true,
openPage: '/frames.html',
historyApiFallback: '/fallback.html',
contentBase: ['.', 'base1', 'base2']
})
]
Expand Down