Skip to content

Commit

Permalink
refactor code to enhance customization
Browse files Browse the repository at this point in the history
  • Loading branch information
Donmclean committed Nov 17, 2017
1 parent 2a829fb commit 352c834
Show file tree
Hide file tree
Showing 19 changed files with 3,712 additions and 4,018 deletions.
2 changes: 1 addition & 1 deletion .babelrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"presets": ["es2015"],
"plugins": ["dynamic-import-node", "syntax-dynamic-import", "react-hot-loader/babel"]
"plugins": ["dynamic-import-node", "syntax-dynamic-import"]
}
19 changes: 9 additions & 10 deletions bin/_setup/electron/electron.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
//TODO: Babel This file in prod build
const electron = require('electron');
// import electron from 'electron';
let config;
if(process.env.NODE_ENV === 'development') {
config = require('./rikoconfig');
}

// Module to control application life.
const app = electron.app;
// Module to create native browser window.
Expand All @@ -24,9 +19,13 @@ function createWindow () {
const options = {};
switch (process.env.NODE_ENV) {
case 'development': {
options.host = `localhost:${config.SERVER_PORT}`;
options.protocol = 'http:';
options.slashes = true;
const rikoconfig = require('./rikoconfig')();
const { webpackConfig } = rikoconfig.setWebpackConfig('electron');

const SERVER_PORT = webpackConfig.devServer.port || 3000;
options.host = `localhost:${SERVER_PORT}`;
options.protocol = 'http:';
options.slashes = true;
break;
}
default: {
Expand Down Expand Up @@ -77,4 +76,4 @@ app.on('activate', function () {
});

// In this file you can include the rest of your app's specific main process
// code. You can also put them in separate files and require them here.
// code. You can also put them in separate files and require them here.
2 changes: 1 addition & 1 deletion bin/_setup/node-server/src/rikoconfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ const config = {
customBoilerplatePath: 'src/riko-custom-boilerplates'
};

module.exports = config;
module.exports = () => config;
2 changes: 1 addition & 1 deletion bin/_setup/react-native/rikoconfig.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module.exports = {};
module.exports = () => {};
33 changes: 26 additions & 7 deletions bin/_setup/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,43 @@
"description": "Hello World boilerplate",
"main": "server.js",
"scripts": {
"flow": "flow check",
"test": "BABEL_ENV=test jest --config ./jestconfig.json",
"test-jest": "BABEL_ENV=test jest --config ./jestconfig.json --coverage",
"test-jest-hot": "BABEL_ENV=test jest -o --config ./jestconfig.json"
"test": "BABEL_ENV=test jest --config ./jestconfig.json --coverage",
"test-jest": "BABEL_ENV=test jest --config ./jestconfig.json --coverage"
},
"dependencies": {
"prop-types": "^15.6.0",
"react": "^16.0.0",
"react-dom": "^16.0.0"
},
"devDependencies": {
"autoprefixer": "^7.1.6",
"babel-jest": "^21.2.0",
"babel-loader": "^7.1.2",
"babel-preset-es2015": "^6.24.1",
"babel-preset-react": "^6.24.1",
"extract-text-webpack-plugin": "^3.0.1",
"browser-sync": "^2.18.13",
"browser-sync-webpack-plugin": "^1.2.0",
"clean-webpack-plugin": "^0.1.17",
"copy-webpack-plugin": "^4.2.0",
"css-loader": "^0.28.7",
"extract-text-webpack-plugin": "^3.0.2",
"file-loader": "^1.1.5",
"handlebars-loader": "^1.6.0",
"html-webpack-plugin": "^2.30.1",
"jest": "^21.2.1",
"jest-cli": "^21.2.1",
"webpack": "^3.8.1"
"less-loader": "^4.0.5",
"node-sass": "^4.6.1",
"postcss-loader": "^2.0.8",
"pug": "^2.0.0-rc.4",
"pug-loader": "^2.3.0",
"react-hot-loader": "^3.1.3",
"sass-loader": "^6.0.6",
"style-loader": "^0.19.0",
"stylus-loader": "^3.0.1",
"url-loader": "^0.6.2",
"webpack": "^3.8.1",
"webpack-dev-server": "^2.9.4",
"webpack-shell-plugin": "^0.5.0"
}
}
}
185 changes: 52 additions & 133 deletions bin/_setup/react/src/rikoconfig.js
Original file line number Diff line number Diff line change
@@ -1,135 +1,54 @@
//**********************************************************************
//*******************************CUSTOM*********************************
//**********************************************************************
const path = require('path');
const cwd = process.cwd();

const config = {
SERVER_PORT: 3000,

setEntry: (entryObject, mainEntryList, immutable) => {
mainEntryList.push('./src/js/index.js');

entryObject.set('index', mainEntryList);

return entryObject;
},

output: {
path: path.resolve(cwd, 'dist')
},

//https://webpack.github.io/docs/configuration.html#devtool
//set to false to disable default source mapping
devtool: (process.env.NODE_ENV === 'production') ? 'source-map' : 'inline-source-map',

setWebpackConfigOptions: (env, config, webpack, immutable) => {
const HtmlWebpackPlugin = require('html-webpack-plugin');

switch (env) {
case 'global': {
config.set('plugins', [
new HtmlWebpackPlugin({
title: 'Riko',

template: 'src/templates/index.pug',
favicon: 'src/media/images/riko-favicon.png',
inject: 'body',
hash: true,
cache: true, //default
showErrors: true, //default

scripts: [
// example
// {
// src: 'https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js',
// async: false,
// defer: false
// }
],
stylesheets: [
// 'https://cdnjs.cloudflare.com/ajax/libs/normalize/4.2.0/normalize.min.css'
]
}),
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify(process.env.NODE_ENV)
}
})
]);
break;
}
case 'production': {
config.set('plugins', [
new webpack.optimize.UglifyJsPlugin({
mangle: true,
sourceMap: true
}),
new webpack.optimize.CommonsChunkPlugin({
name: 'index',
filename: 'assets/js/[name].[hash].min.js'
})
]);
break;
}
case 'development': {
break;
}
default: {
break;
module.exports = () => {
return {
setWebpackConfig: () => {
//return an object with the following keys 'webpack', 'webpackDevServer', 'webpackConfig'
//i.e: { webpack: require('webpack'), webpackDevServer: require('webpack-dev-server'), webpackConfig: require('../webpack.config.babel')}

const webpack = require('webpack');
const webpackDevServer = require('webpack-dev-server');
const webpackConfig = require('../webpack.config.babel');

return { webpack, webpackDevServer, webpackConfig };
},

setCustomBoilerplatePath: () => {
//return a string which is the relative path to your custom boilerplate directory
//return false to disable custom boilerplate creation
return 'src/riko-custom-boilerplates';
},

setWebpackEventHooks: (NODE_ENV) => {
//return an object with the keys as the event names and the values as the event callback functions
//see here for more details: https://webpack.js.org/api/compiler/#event-hooks

//i.e:
// return {
// 'before-compile': (compilation, callback) => {
// // Do something async on the before-compile event...
// callback();
// }
// };

return {};
},

setElectronPackagerOptions: () => {
//return an object containing electron packager options
//for Electron Applications Only
//See API for all options here: https://github.com/electron-userland/electron-packager/blob/master/docs/api.md
return {
name: 'Riko',

//applications icon //OS X: .icns //Windows: .ico
//get free conversions herehttps://iconverticons.com/online/
icon: 'src/riko-logo.icns',

//target platform(s) to build for
platform: 'all',

//Enable or disable asar archiving
asar: true
}
}
},

//**********************************************************************
//*******************************ELECTRON*******************************
//**********************************************************************
//for Electron Applications Only
//See API for all options here: https://github.com/electron-userland/electron-packager/blob/master/docs/api.md
electronPackagerOptions: {
name: 'Riko',

//applications icon //OS X: .icns //Windows: .ico
//get free conversions herehttps://iconverticons.com/online/
icon: 'src/riko-logo.icns',

//target platform(s) to build for
platform: 'all',

//Enable or disable asar archiving
asar: true
},
//**********************************************************************

hotReloadingOptions: {
overlay: true,

//Override hot module replacement and simply have the page refresh on file change
browserSyncReloadOnChange: false,

//Provide an npm package.json script command here to have tests execute on every webpack rebuild.
//i.e: 'test' would execute as 'npm run test' or 'hot-test' as 'npm run hot-test'
hotExecuteTestCommand: 'test',

hotExecuteFlowTypeCommand: 'default'
},

//prefix everything: browsers: ['> 0%']
autoprefixerOptions: {
browsers: ['> 0%']
},

//Specific custom boilerplate path for generating path boilerplate files via the `riko <create>` command.
//Path must be relative to package.json.
customBoilerplatePath: 'src/riko-custom-boilerplates'
};

//**********************************************************************
//****************************EXTERNALS*********************************
//**********************************************************************

// To add vendor dependencies and expose them to global/window object simply use the expose-loader
// eg: require("expose-loader?_!lodash");
// see: https://github.com/webpack/expose-loader

module.exports = config;
}
};
Loading

0 comments on commit 352c834

Please sign in to comment.