Skip to content

Commit

Permalink
Github Pages demo page
Browse files Browse the repository at this point in the history
  • Loading branch information
vkruglikov committed Jan 2, 2025
1 parent bcd7653 commit d26fce9
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 17 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/demo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Deploy @msw-devtools/demo

on:
push:
branches: ['master']
paths:
- 'packages/demo/**'
- '.github/workflows/demo.yml'

permissions:
contents: read
pages: write
id-token: write

jobs:
deploy-demo:
name: Install dependencies
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/setup-node
- uses: ./.github/actions/install-npm-deps

- name: Build all packages
run: npm run build -- --filter=@msw-devtools/demo

- name: Setup Pages
uses: actions/configure-pages@v2

- name: Upload artifact
uses: actions/upload-pages-artifact@v1
with:
path: './packages/demo/dist/.'

- name: Deploy GitHub Pages
id: deployment
uses: actions/deploy-pages@v1
5 changes: 2 additions & 3 deletions packages/demo/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "@msw-devtools/demo",
"version": "0.1",
"author": "Valentin Kruglikov",
"license": "MIT",
"scripts": {
"dev": "NODE_ENV=development npx webpack serve",
Expand All @@ -11,8 +12,6 @@
"@msw-devtools/json-config": "*"
},
"msw": {
"workerDirectory": [
"dist"
]
"workerDirectory": "./public"
}
}
2 changes: 1 addition & 1 deletion packages/demo/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ <h3>Demo msw</h3>
<p>
<label>
url:
<input id="url" value="test" type="text" />
<input id="url" value="/test" type="text" />
</label>
</p>
<p>
Expand Down
8 changes: 7 additions & 1 deletion packages/demo/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@ import { http } from 'msw'
const handlers = [http.all('*', createResponseResolver())]

setupWorker(...handlers).start({
onUnhandledRequest: 'bypass'
onUnhandledRequest: 'bypass',
serviceWorker: {
url:
process.env.NODE_ENV === 'production'
? '/msw-devtools-extension/mockServiceWorker.js'
: '/mockServiceWorker.js'
}
})
;(document.getElementById('form') as HTMLFormElement).addEventListener(
'submit',
Expand Down
28 changes: 16 additions & 12 deletions webpack.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ const path = require('path')
const webpack = require('webpack')
const CopyPlugin = require('copy-webpack-plugin')

const IS_DEV = process.env.NODE_ENV === 'development'

module.exports = ({ root, port, wdsClient = true }) => ({
module: {
rules: [
Expand All @@ -27,18 +29,20 @@ module.exports = ({ root, port, wdsClient = true }) => ({
}
]
},
devtool: 'inline-source-map',
devServer: {
port,
compress: true,
static: {
directory: path.join(root, 'dist')
},
client: wdsClient ? undefined : false,
devMiddleware: {
writeToDisk: true
}
},
devtool: IS_DEV ? 'inline-source-map' : false,
devServer: IS_DEV
? {
port,
compress: true,
static: {
directory: path.join(root, 'dist')
},
client: wdsClient ? undefined : false,
devMiddleware: {
writeToDisk: true
}
}
: false,
resolve: {
extensions: ['.tsx', '.ts', '.js']
},
Expand Down

0 comments on commit d26fce9

Please sign in to comment.