Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben Howl committed Dec 19, 2018
0 parents commit 60e76a0
Show file tree
Hide file tree
Showing 15 changed files with 6,124 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"presets": [
"@babel/preset-react",
[
"@babel/preset-env",
{
"targets": ">0.25%, not ie 11, not op_mini all"
}
]
]
}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/node_modules
yarn-error.log
Empty file added .nvmrc
Empty file.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## Example of React and worker-plugin (https://github.com/GoogleChromeLabs/worker-plugin)

- Clone repo
- yarn serve
- Go to http://localhost:5000
1 change: 1 addition & 0 deletions dist/0.worker.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions dist/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Worker plugin example</title>
</head>

<body>
<div id="root" />
<script type="text/javascript" src="main.js"></script></body>

</html>
31 changes: 31 additions & 0 deletions dist/main.js

Large diffs are not rendered by default.

39 changes: 39 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"name": "webpack-worker-plugin-react-example",
"version": "0.1.0",
"main": "index.js",
"scripts": {
"start": "webpack-dev-server --mode development --hot",
"build": "webpack --mode production",
"serve": "yarn build && ./node_modules/.bin/serve -s dist",
"lint": "yarn standard --fix"
},
"license": "MIT",
"devDependencies": {
"@babel/core": "^7.2.0",
"@babel/preset-env": "^7.2.0",
"@babel/preset-react": "^7.0.0",
"babel-loader": "^8.0.4",
"clean-webpack-plugin": "^1.0.0",
"html-webpack-plugin": "^3.2.0",
"standard": "^12.0.1",
"webpack-cli": "^3.1.2",
"webpack-dev-server": "^3.1.10",
"worker-plugin": "^2.0.1",
"serve": "^10.1.1"
},
"dependencies": {
"react": "^16.7.0-alpha.2",
"react-dom": "^16.7.0-alpha.2",

"webpack": "4.26.1"
},
"standard": {
"globals": [
"self",
"Worker",
"addEventListener",
"postMessage"
]
}
}
19 changes: 19 additions & 0 deletions src/components/app/app.component.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import React from 'react'
const basicWorker = new Worker('../../workers/basicWorker.js', { type: 'module' })

const App = () => {
const postMessageToWorker = () => {
basicWorker.postMessage('Bonjour Monsieur worker, it is me the Main Thread.')
}

return (
(
<>
<div>Look in the browser console</div>
<button onClick={postMessageToWorker}>Press me</button>
</>
)
)
}

export default App
3 changes: 3 additions & 0 deletions src/components/app/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import App from './app.component'

export default App
15 changes: 15 additions & 0 deletions src/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Worker plugin example</title>
</head>

<body>
<div id="root" />
</body>

</html>
11 changes: 11 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import React from 'react'
import ReactDOM from 'react-dom'
import App from './components/app'

const Root = () => (
<>
<App />
</>
)

ReactDOM.render(<Root />, document.getElementById('root'))
5 changes: 5 additions & 0 deletions src/workers/basicWorker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
console.log('*** I AM WORKER ***')

addEventListener('message', event => {
console.log('WORKER received this message: ', event.data)
})
31 changes: 31 additions & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const path = require('path')

const HtmlWebPackPlugin = require('html-webpack-plugin')
const CleanPlugin = require('clean-webpack-plugin')

const htmlPlugin = new HtmlWebPackPlugin({
template: './src/index.html',
filename: './index.html'
})

const WorkerPlugin = require('worker-plugin')

module.exports = {
output: {
filename: '[name].js',
path: path.resolve(__dirname, 'dist'),
globalObject: 'self'
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader'
}
}
]
},
plugins: [new CleanPlugin(['dist']), htmlPlugin, new WorkerPlugin()]
}
Loading

0 comments on commit 60e76a0

Please sign in to comment.