Skip to content
This repository was archived by the owner on Jan 20, 2022. It is now read-only.

Commit 58e51d2

Browse files
committed
Create test repo
1 parent 480caf6 commit 58e51d2

File tree

8 files changed

+346
-0
lines changed

8 files changed

+346
-0
lines changed

package.json

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
{
2+
"name": "test",
3+
"version": "1.0.0",
4+
"private": true,
5+
"scripts": {
6+
"start": "node_modules/.bin/cross-env NODE_ENV=development node_modules/.bin/webpack-dev-server --colors --config webpack.config.js --port 8080",
7+
"build": "node_modules/.bin/cross-env NODE_ENV=production node_modules/.bin/webpack --config webpack.config.js -p"
8+
},
9+
"engines": {
10+
"node": ">=7.4.0",
11+
"npm": ">=4.0.5"
12+
},
13+
"dependencies": {
14+
"babel-polyfill": "^6.23.0",
15+
"classnames": "^2.2.5",
16+
"connected-react-router": "^4.2.1",
17+
"document-ready-promise": "^3.0.1",
18+
"history": "^4.6.1",
19+
"lodash": "^4.17.4",
20+
"normalize.css": "^7.0.0",
21+
"promise-native-deferred": "^3.0.0",
22+
"prop-types": "^15.5.10",
23+
"react": "^15.5.4",
24+
"react-css-themr": "^2.1.2",
25+
"react-document-title": "^2.0.3",
26+
"react-dom": "^15.5.4",
27+
"react-redux": "^5.0.4",
28+
"react-router": "^4.1.1",
29+
"react-router-dom": "^4.1.1",
30+
"react-toolbox": "^2.0.0-beta.8",
31+
"recompose": "^0.23.4",
32+
"redux": "^3.6.0",
33+
"redux-actions": "^2.0.3",
34+
"redux-devtools-extension": "^2.13.2",
35+
"redux-form": "^6.7.0",
36+
"redux-saga": "^0.15.3",
37+
"store": "^2.0.4"
38+
},
39+
"devDependencies": {
40+
"autoprefixer": "^7.1.0",
41+
"babel-core": "^6.24.1",
42+
"babel-eslint": "^7.2.3",
43+
"babel-loader": "^7.0.0",
44+
"babel-plugin-idx": "^1.5.1",
45+
"babel-plugin-react-transform": "^2.0.2",
46+
"babel-plugin-transform-dirname-filename": "^1.1.0",
47+
"babel-plugin-transform-node-env-inline": "^6.8.0",
48+
"babel-preset-es2015": "^6.24.1",
49+
"babel-preset-react": "^6.24.1",
50+
"babel-preset-stage-1": "^6.24.1",
51+
"cross-env": "^5.0.0",
52+
"css-loader": "^0.28.1",
53+
"eslint": "^3.19.0",
54+
"eslint-plugin-import": "^2.2.0",
55+
"eslint-plugin-jsx-control-statements": "^2.1.1",
56+
"eslint-plugin-react": "^7.0.1",
57+
"jsx-control-statements": "^3.1.5",
58+
"postcss-cssnext": "^2.9.0",
59+
"postcss-each": "^0.9.3",
60+
"postcss-import": "^10.0.0",
61+
"postcss-loader": "^2.0.5",
62+
"postcss-mixins": "^6.0.0",
63+
"react-hot-loader": "^3.0.0-beta.6",
64+
"redux-logger": "^3.0.1",
65+
"style-loader": "^0.17.0",
66+
"stylelint": "^7.10.1",
67+
"stylelint-config-standard": "^16.0.0",
68+
"webpack": "^2.5.1",
69+
"webpack-dev-server": "^2.4.5"
70+
}
71+
}

postcss.config.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
module.exports = context => ({
2+
options: {
3+
sourceMap: true
4+
},
5+
plugins: {
6+
'postcss-import': {
7+
path: [
8+
'node_modules',
9+
'src/main/react', // allows importing modules using absolute path, @see https://goo.gl/luH0Xa
10+
]
11+
},
12+
'postcss-mixins': {},
13+
'postcss-each': {},
14+
'postcss-cssnext': {
15+
features: {
16+
customProperties: {
17+
variables: {
18+
'color-primary': 'var(--palette-indigo-500)',
19+
'color-primary-dark': 'var(--palette-indigo-700)',
20+
'color-primary-light': 'var(--palette-indigo-500)',
21+
'color-accent': 'var(--palette-pink-a200)',
22+
'color-accent-dark': 'var(--palette-pink-700)',
23+
'color-primary-contrast': 'var(--color-dark-contrast)',
24+
'color-accent-contrast': 'var(--color-dark-contrast)'
25+
}
26+
}
27+
},
28+
browsers: ['last 2 versions', '> 5%'],
29+
},
30+
},
31+
});

src/main/react/Layout.css

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
@import "react-toolbox/lib/colors.css";
2+
3+
body {
4+
padding: 0;
5+
margin: 0;
6+
background-color: var(--palette-grey-200);
7+
}
8+
9+
/* http://stackoverflow.com/questions/5939341/firefox-4-is-there-a-way-to-remove-the-red-border-in-a-required-form-input */
10+
input:required {
11+
box-shadow: none;
12+
}

src/main/react/Layout.js

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import React, { Component } from 'react'
2+
import { Layout as RTLayout, NavDrawer, Panel } from 'react-toolbox'
3+
import { AppBar } from 'react-toolbox'
4+
import isBrowser from 'react-toolbox/lib/utils/is-browser'
5+
import breakpoints from 'react-toolbox/lib/utils/breakpoints'
6+
import { getViewport } from 'react-toolbox/lib/utils/utils'
7+
import DocumentTitle from 'react-document-title'
8+
import 'Layout.css'
9+
10+
class Layout extends Component {
11+
state = {
12+
drawerActive: false,
13+
width: isBrowser() && getViewport().width
14+
}
15+
16+
permanentAt = 'lg'
17+
18+
toggleDrawerActive = () => {
19+
this.setState({ drawerActive: !this.state.drawerActive })
20+
}
21+
22+
componentDidMount () {
23+
if (!this.state.width) this.handleResize()
24+
window.addEventListener('resize', this.handleResize)
25+
}
26+
27+
hideDrawer = () => {
28+
this.setState({ drawerActive: false })
29+
}
30+
31+
componentWillUnmount () {
32+
window.removeEventListener('resize', this.handleResize)
33+
}
34+
35+
handleResize = () => {
36+
this.setState({ width: getViewport().width })
37+
}
38+
39+
render() {
40+
const appBarIconVisible = this.state.width <= breakpoints[this.permanentAt]
41+
42+
let appBarIcon
43+
if (appBarIconVisible) {
44+
appBarIcon = 'menu'
45+
}
46+
47+
const navDrawerProps = {
48+
active: this.state.drawerActive,
49+
permanentAt: this.permanentAt,
50+
onOverlayClick: this.toggleDrawerActive
51+
}
52+
53+
return (
54+
<DocumentTitle title="Test">
55+
<RTLayout>
56+
<NavDrawer { ...navDrawerProps }>
57+
<ul>
58+
<li>Menu item 1</li>
59+
<li>Menu item 2</li>
60+
</ul>
61+
</NavDrawer>
62+
<Panel>
63+
<AppBar
64+
title="Test"
65+
leftIcon={appBarIcon}
66+
onLeftIconClick={this.toggleDrawerActive}
67+
/>
68+
<div>
69+
Hello world
70+
</div>
71+
</Panel>
72+
</RTLayout>
73+
</DocumentTitle>
74+
)
75+
}
76+
}
77+
78+
export default Layout

src/main/react/index.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import React from 'react'
2+
import ReactDOM from 'react-dom'
3+
import { AppContainer } from 'react-hot-loader'
4+
import Layout from './Layout'
5+
6+
console.log('process.env.NODE_ENV =', process.env.NODE_ENV)
7+
8+
const rootEl = document.getElementById('root')
9+
10+
const render = () => {
11+
console.debug('render()')
12+
ReactDOM.render(
13+
// Root component should be placed in separate file (module) to allow hot reload
14+
// React Router leaves a warning (Warning: [react-router] You cannot change <Router routesGen>; it will be ignored)
15+
// but it seems that hot reloading of routed components works.
16+
<AppContainer>
17+
<Layout />
18+
</AppContainer>,
19+
rootEl
20+
)
21+
}
22+
23+
if (process.env.NODE_ENV !== 'production') {
24+
// Should be gone @see https://github.com/react-toolbox/react-toolbox/pull/1164#issuecomment-276338422
25+
const { overrideComponentTypeChecker } = require('react-toolbox')
26+
const isComponentOfType = (classType, reactElement) => (
27+
reactElement && reactElement.type && (
28+
reactElement.type === classType ||
29+
reactElement.type.name === classType.displayName
30+
)
31+
)
32+
overrideComponentTypeChecker(isComponentOfType)
33+
if (module.hot) {
34+
module.hot.accept('./Layout', render)
35+
}
36+
}
37+
38+
render()

src/main/react/util/ProductionInit.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// nothing here yet ;)
2+
// it may remain empty, but this one is added to main entry point automatically in webpack.config.js,
3+
// so leave this file even if it's empty

src/main/webapp/index.html

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1">
6+
<title>Test</title>
7+
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
8+
<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700" rel="stylesheet">
9+
</head>
10+
<body>
11+
<div id="root"></div>
12+
<script src="http://localhost:8080/asset/test.js"></script>
13+
</body>
14+
</html>

webpack.config.js

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
const path = require('path');
2+
const webpack = require('webpack');
3+
4+
const noop = () => {}
5+
// simple DSL to allow writing simple switch: `dev('dev setting').prod('prod setting')`
6+
const dev = (dev) => {
7+
return {
8+
prod: (prod) => {
9+
if (process.env.NODE_ENV === 'production') {
10+
return prod
11+
} else {
12+
return dev
13+
}
14+
}
15+
}
16+
}
17+
18+
const webpackPort = 8080
19+
20+
const settings = {
21+
entry: {
22+
test: [
23+
dev('react-hot-loader/patch').prod('./src/main/react/util/ProductionInit.js'),
24+
'babel-polyfill',
25+
'./src/main/react/index.js'
26+
]
27+
},
28+
output: {
29+
filename: '[name].js',
30+
publicPath: dev(`http://localhost:${webpackPort}/asset/`).prod('/asset/'),
31+
path: path.resolve('src/main/webapp/asset')
32+
},
33+
resolve: {
34+
extensions: ['.js', '.json', '.css'],
35+
modules: [
36+
'node_modules',
37+
'src/main/react', // allows importing modules using absolute path, @see https://goo.gl/luH0Xa
38+
]
39+
},
40+
devtool: dev('eval-source-map').prod('source-map'), // this emits sources while development making it easier to debug
41+
module: {
42+
rules: [
43+
{
44+
test: /\.js$/,
45+
loader: 'babel-loader',
46+
options: {
47+
presets: [
48+
['es2015', { modules: false }],
49+
'stage-1',
50+
'react'
51+
],
52+
plugins: [
53+
'transform-node-env-inline',
54+
'jsx-control-statements',
55+
'transform-dirname-filename',
56+
'idx', // http://facebook.github.io/react-native/blog/2017/03/13/idx-the-existential-function.html
57+
],
58+
env: {
59+
development: {
60+
plugins: ['react-hot-loader/babel']
61+
}
62+
}
63+
}
64+
},
65+
{
66+
test: /\.css$/,
67+
use: [
68+
'style-loader',
69+
{
70+
loader: 'css-loader',
71+
options: {
72+
modules: true,
73+
sourceMap: true,
74+
importLoaders: 1,
75+
localIdentName: dev('[name]--[local]--[hash:base64:5]').prod('[hash:base64]')
76+
}
77+
},
78+
'postcss-loader' // has separate config nearby
79+
]
80+
},
81+
]
82+
},
83+
devServer: {
84+
contentBase: path.resolve('src/main/webapp'),
85+
publicPath: `http://localhost:${webpackPort}/asset/`, // full URL is necessary for Hot Module Replacement.
86+
quiet: false,
87+
hot: true,
88+
historyApiFallback: true,
89+
inline: true
90+
},
91+
plugins: [
92+
dev(new webpack.HotModuleReplacementPlugin()).prod(noop),
93+
dev(new webpack.NamedModulesPlugin()).prod(noop)
94+
]
95+
};
96+
97+
//process.stdout.write(JSON.stringify(settings, null, ' '));
98+
99+
module.exports = settings;

0 commit comments

Comments
 (0)