Переглянути джерело

added webpack-based frontend (incl. react/redux) template

Brandon Wong 7 роки тому
батько
коміт
748422dd24

+ 9 - 0
frontend-blank/.babelrc

@@ -0,0 +1,9 @@
+{
+  "presets": ["latest", "react"],
+  "plugins": ["transform-runtime", "transform-object-rest-spread"],
+  "env": {
+    "production": {
+      "plugins": ["transform-remove-console"]
+    }
+  }
+}

+ 8 - 0
frontend-blank/.gitignore

@@ -0,0 +1,8 @@
+.idea
+node_modules
+build
+test-build
+npm-debug*
+*.swp
+public/assets/*
+!public/assets/.gitkeep

+ 37 - 0
frontend-blank/package.json

@@ -0,0 +1,37 @@
+{
+  "name": "@brwong/$foldername",
+  "author": "Brandon Wong",
+  "version": "0.1.0",
+  "main": "index.js",
+  "scripts": {
+    "test": "node test/index.js",
+    "watch": "webpack -d --display-error-details --progress --watch",
+    "serve": "http-server -a 127.0.0.1",
+    "testwatch": "nodemon --watch src --watch test --exec \"npm test\""
+  },
+  "devDependencies": {
+    "babel-core": "^6.23.1",
+    "babel-loader": "^6.3.2",
+    "babel-plugin-transform-object-rest-spread": "^6.23.0",
+    "babel-plugin-transform-remove-console": "^6.8.0",
+    "babel-plugin-transform-runtime": "^6.23.0",
+    "babel-polyfill": "^6.20.0",
+    "babel-preset-latest": "^6.22.0",
+    "babel-preset-react": "^6.23.0",
+    "babel-register": "^6.18.0",
+    "css-loader": "^0.26.1",
+    "extract-text-webpack-plugin": "^2.0.0-rc.3",
+    "file-loader": "^0.10.0",
+    "http-server": "^0.9.0",
+    "node-sass": "^4.5.0",
+    "nodemon": "^1.11.0",
+    "sass-loader": "^6.0.0",
+    "style-loader": "^0.13.1",
+    "tape-promise": "^2.0.1",
+    "tape": "^4.6.3",
+    "url-loader": "^0.5.7",
+    "webpack": "^2.2.1"
+  },
+  "description": "",
+  "private": true
+}

+ 0 - 0
frontend-blank/public/assets/.gitkeep


+ 11 - 0
frontend-blank/public/index.html

@@ -0,0 +1,11 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <title>$foldername</title>
+    <link rel="stylesheet" href="/assets/style.css">
+</head>
+<body>
+<script src="/assets/script.js"></script>
+</body>
+</html>

+ 6 - 0
frontend-blank/src/index.js

@@ -0,0 +1,6 @@
+
+import _styles from './style/index.scss';
+
+console.log('hello');
+
+

+ 4 - 0
frontend-blank/src/style/index.scss

@@ -0,0 +1,4 @@
+
+/* styles go here */
+
+

+ 8 - 0
frontend-blank/test/main.js

@@ -0,0 +1,8 @@
+
+require('babel-register')({
+    "presets": ["latest", "react"],
+    "plugins": ["transform-runtime", "transform-object-rest-spread"],
+});
+require('babel-polyfill');
+require('./suite.js');
+

+ 16 - 0
frontend-blank/test/suite.js

@@ -0,0 +1,16 @@
+
+import tape from 'tape';
+import _test from 'tape-promise';
+
+const tapetest = _test(tape);
+
+import * as reducers from '../src/reducers/index.js';
+import * as actions from '../src/actions.js';
+
+
+tapetest('test', async function testProgram(t) {
+    t.pass('empty test file');
+    t.end();
+});
+
+

+ 33 - 0
frontend-blank/webpack.config.js

@@ -0,0 +1,33 @@
+const webpack = require("webpack");
+const path = require('path');
+
+const ExtractTextPlugin = require('extract-text-webpack-plugin');
+
+module.exports = {
+    entry: {
+        script: path.resolve(__dirname, 'src', 'index.js'),
+    },
+    output: {
+        path: path.resolve(__dirname, 'public', 'assets'),
+        filename: '[name].js',
+        chunkFilename: '[name].js',
+        publicPath: '/assets/'
+    },
+    module: {
+        rules: [
+            { test: /\.scss$/, use: ExtractTextPlugin.extract({ fallback: "style-loader", use: ["css-loader", "sass-loader"], publicPath: "/assets" }), exclude: /node_modules/ },
+            { test: /\.js$/, use: "babel-loader", exclude: /node_modules/ },
+            { test: /\.(woff|woff2)(\?v=\d+\.\d+\.\d+)?$/, loader: 'url-loader?limit=10000&mimetype=application/font-woff' },
+            { test: /\.ttf(\?v=\d+\.\d+\.\d+)?$/, loader: 'url-loader?limit=10000&mimetype=application/octet-stream' },
+            { test: /\.svg(\?v=\d+\.\d+\.\d+)?$/, loader: 'url-loader?limit=10000&mimetype=application/octet-stream' },
+            { test: /\.eot(\?v=\d+\.\d+\.\d+)?$/, loader: 'file-loader' },
+        ],
+    },
+    plugins: [
+        new ExtractTextPlugin({
+            filename: "style.css",
+            disable: false,
+            allChunks: true
+        }),
+    ],
+};

Різницю між файлами не показано, бо вона завелика
+ 3383 - 0
frontend-blank/yarn.lock


+ 9 - 0
frontend/.babelrc

@@ -0,0 +1,9 @@
+{
+  "presets": ["latest", "react"],
+  "plugins": ["transform-runtime", "transform-object-rest-spread"],
+  "env": {
+    "production": {
+      "plugins": ["transform-remove-console"]
+    }
+  }
+}

+ 8 - 0
frontend/.gitignore

@@ -0,0 +1,8 @@
+.idea
+node_modules
+build
+test-build
+npm-debug*
+*.swp
+public/assets/*
+!public/assets/.gitkeep

+ 46 - 0
frontend/package.json

@@ -0,0 +1,46 @@
+{
+  "name": "@brwong/$foldername",
+  "author": "Brandon Wong",
+  "version": "0.1.0",
+  "main": "index.js",
+  "scripts": {
+    "test": "node test/index.js",
+    "watch": "webpack -d --display-error-details --progress --watch",
+    "serve": "http-server -a 127.0.0.1",
+    "testwatch": "nodemon --watch src --watch test --exec \"npm test\""
+  },
+  "devDependencies": {
+    "babel-core": "^6.23.1",
+    "babel-loader": "^6.3.2",
+    "babel-plugin-transform-object-rest-spread": "^6.23.0",
+    "babel-plugin-transform-remove-console": "^6.8.0",
+    "babel-plugin-transform-runtime": "^6.23.0",
+    "babel-polyfill": "^6.20.0",
+    "babel-preset-latest": "^6.22.0",
+    "babel-preset-react": "^6.23.0",
+    "babel-register": "^6.18.0",
+    "css-loader": "^0.26.1",
+    "extract-text-webpack-plugin": "^2.0.0-rc.3",
+    "file-loader": "^0.10.0",
+    "http-server": "^0.9.0",
+    "node-sass": "^4.5.0",
+    "nodemon": "^1.11.0",
+    "react": "^15.4.2",
+    "react-dom": "^15.4.2",
+    "react-redux": "^5.0.3",
+    "redux": "^3.6.0",
+    "redux-thunk": "^2.2.0",
+    "sass-loader": "^6.0.0",
+    "style-loader": "^0.13.1",
+    "tape-promise": "^2.0.1",
+    "tape": "^4.6.3",
+    "url-loader": "^0.5.7",
+    "webpack": "^2.2.1"
+  },
+  "dependencies": {
+    "css-loader": "^0.26.2",
+    "style-loader": "^0.13.2",
+    "url-loader": "^0.5.8"
+  },
+  "private": true
+}

+ 0 - 0
frontend/public/assets/.gitkeep


+ 12 - 0
frontend/public/index.html

@@ -0,0 +1,12 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <title>$foldername</title>
+    <link rel="stylesheet" href="/assets/style.css">
+</head>
+<body>
+    <div id="container"></div>
+    <script src="/assets/script.js"></script>
+</body>
+</html>

+ 8 - 0
frontend/src/actions.js

@@ -0,0 +1,8 @@
+
+
+export function action() {
+    return {
+        type: 'ACTION',
+    };
+}
+

+ 9 - 0
frontend/src/components/App.js

@@ -0,0 +1,9 @@
+
+import React from 'react';
+
+
+export default function App() {
+    return <div>application</div>;
+}
+
+

+ 23 - 0
frontend/src/components/ExampleContainer.js

@@ -0,0 +1,23 @@
+
+import React from 'react';
+import { connect } from 'react-redux';
+import ExampleComponent from './ExampleComponent.js';
+
+
+function ExampleContainer(props) {
+    return <div>
+            <ExampleComponent />
+        </div>;
+}
+
+
+function stateToProps(state) {
+    return {};
+}
+function dispatchToProps(dispatch) {
+    return {};
+}
+
+export default connect(stateToProps, dispatchToProps)(ExampleContainer);
+
+

+ 27 - 0
frontend/src/index.js

@@ -0,0 +1,27 @@
+
+import _styles from './style/index.scss';
+import React from 'react';
+import ReactDOM from 'react-dom';
+import { Provider } from 'react-redux';
+import { createStore, applyMiddleware } from 'redux';
+//import thunkMiddleware from 'redux-thunk';
+
+import reducers from './reducers/index.js';
+import App from './components/App.js';
+
+/*
+ex:
+createStore(reducer, applyMiddleware(thunkMiddleware))
+*/
+
+const store = createStore(reducers, /*initialState,*/ window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__());
+
+ReactDOM.render(
+    <Provider store={store}>
+        <App />
+    </Provider>,
+    document.getElementById('container')
+);
+
+
+

+ 12 - 0
frontend/src/reducers/exampleReducer.js

@@ -0,0 +1,12 @@
+
+
+const defaultState = Object.freeze({});
+
+export default function example(state = defaultState, action = {type:'NO-OP'}) {
+    switch( action.type ) {
+        default:
+            return state;
+    }
+}
+
+

+ 11 - 0
frontend/src/reducers/index.js

@@ -0,0 +1,11 @@
+
+import { combineReducers } from 'redux';
+//import reducer from './reducer.js';
+
+const mainReducer = combineReducers({
+    
+});
+
+export { mainReducer as default };
+
+

+ 4 - 0
frontend/src/style/index.scss

@@ -0,0 +1,4 @@
+
+/* styles go here */
+
+

+ 8 - 0
frontend/test/main.js

@@ -0,0 +1,8 @@
+
+require('babel-register')({
+    "presets": ["latest", "react"],
+    "plugins": ["transform-runtime", "transform-object-rest-spread"],
+});
+require('babel-polyfill');
+require('./suite.js');
+

+ 16 - 0
frontend/test/suite.js

@@ -0,0 +1,16 @@
+
+import tape from 'tape';
+import _test from 'tape-promise';
+
+const tapetest = _test(tape);
+
+import * as reducers from '../src/reducers/index.js';
+import * as actions from '../src/actions.js';
+
+
+tapetest('test', async function testProgram(t) {
+    t.pass('empty test file');
+    t.end();
+});
+
+

+ 33 - 0
frontend/webpack.config.js

@@ -0,0 +1,33 @@
+const webpack = require("webpack");
+const path = require('path');
+
+const ExtractTextPlugin = require('extract-text-webpack-plugin');
+
+module.exports = {
+    entry: {
+        script: path.resolve(__dirname, 'src', 'index.js'),
+    },
+    output: {
+        path: path.resolve(__dirname, 'public', 'assets'),
+        filename: '[name].js',
+        chunkFilename: '[name].js',
+        publicPath: '/assets/'
+    },
+    module: {
+        rules: [
+            { test: /\.scss$/, use: ExtractTextPlugin.extract({ fallback: "style-loader", use: ["css-loader", "sass-loader"], publicPath: "/assets" }), exclude: /node_modules/ },
+            { test: /\.js$/, use: "babel-loader", exclude: /node_modules/ },
+            { test: /\.(woff|woff2)(\?v=\d+\.\d+\.\d+)?$/, loader: 'url-loader?limit=10000&mimetype=application/font-woff' },
+            { test: /\.ttf(\?v=\d+\.\d+\.\d+)?$/, loader: 'url-loader?limit=10000&mimetype=application/octet-stream' },
+            { test: /\.svg(\?v=\d+\.\d+\.\d+)?$/, loader: 'url-loader?limit=10000&mimetype=application/octet-stream' },
+            { test: /\.eot(\?v=\d+\.\d+\.\d+)?$/, loader: 'file-loader' },
+        ],
+    },
+    plugins: [
+        new ExtractTextPlugin({
+            filename: "style.css",
+            disable: false,
+            allChunks: true
+        }),
+    ],
+};

Різницю між файлами не показано, бо вона завелика
+ 3383 - 0
frontend/yarn.lock