Skip to content

Commit

Permalink
init project
Browse files Browse the repository at this point in the history
  • Loading branch information
chentsulin committed May 18, 2015
0 parents commit 9d7637e
Show file tree
Hide file tree
Showing 22 changed files with 393 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
root = true

[*]
indent_style = tab
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.{json,js}]
indent_style = space
indent_size = 2

[*.md]
trim_trailing_whitespace = false
16 changes: 16 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"env": {
"node": true,
"mocha": true,
"es6": true
},
"globals": {

},
"rules": {
"quotes": [2, "single"]
"semi": [2, "never"],
"curly": [2, "multi-line"],
"no-underscore-dangle": 0
}
}
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto
27 changes: 27 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Logs
logs
*.log

# Runtime data
pids
*.pid
*.seed

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directory
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
node_modules
Empty file added CHANGELOG.md
Empty file.
22 changes: 22 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
The MIT License (MIT)

Copyright (c) 2015 C. T. Lin

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# electron-react-boilerplate

> WIP
Empty file added app/actions/.gitkeep
Empty file.
Empty file added app/app.js
Empty file.
Empty file added app/components/HelloWorld.jsx
Empty file.
Empty file added app/dispatcher/.gitkeep
Empty file.
Empty file added app/stores/.gitkeep
Empty file.
10 changes: 10 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<title>Hello Electron React!</title>
</head>
<body>
<div id="react-root"></div>
<script src=""></script>
</body>
</html>
29 changes: 29 additions & 0 deletions lib/loaders-by-extension.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
function extsToRegExp(exts) {
return new RegExp('\\.(' + exts.map(function(ext) {
return ext.replace(/\./g, '\\.')
}).join('|') + ')(\\?.*)?$')
}

module.exports = function loadersByExtension(obj) {
var loaders = []
Object.keys(obj).forEach(function(key) {
var exts = key.split('|')
var value = obj[key]
var entry = {
extensions: exts,
test: extsToRegExp(exts),
}

if (Array.isArray(value)) {
entry.loaders = value
} else if (typeof value === 'string') {
entry.loader = value
} else {
Object.keys(value).forEach(function(valueKey) {
entry[valueKey] = value[valueKey]
})
}
loaders.push(entry)
})
return loaders
};
28 changes: 28 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
var app = require('app')
var BrowserWindow = require('browser-window')

require('crash-reporter').start()

var mainWindow = null

app.on('window-all-closed', function() {
if (process.platform != 'darwin')
app.quit()
})


app.on('ready', function() {

mainWindow = new BrowserWindow({ width: 800, height: 600 })

mainWindow.loadUrl('file://' + __dirname + '/index.html')

mainWindow.on('closed', function() {
mainWindow = null
})

if (process.env.NODE_ENV !== 'production') {
mainWindow.openDevTools()
}

})
172 changes: 172 additions & 0 deletions make-webpack-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
var webpack = require('webpack')
var path = require('path')
var ExtractTextPlugin = require('extract-text-webpack-plugin')
var StatsPlugin = require('stats-webpack-plugin')
var loadersByExtension = require('./lib/loaders-by-extension')



module.exports = function(opts) {

var entry = [
'webpack-dev-server/client?http://localhost:2992',
'webpack/hot/only-dev-server',
'./app/scripts/app.jsx'
]



var loaders = [
{ test: /\.(js|jsx)$/, loaders: [ 'react-hot', 'babel' ], exclude: /node_modules/ },
{ test: /\.styl$/, loaders: [ 'style', 'css', 'stylus' ], exclude: /node_modules/ },
{ test: /\.css$/, loaders: [ 'style', 'css' ], exclude: /node_modules/ },
{ test: /\.json$/, loader: 'json', exclude: /node_modules/ },
{ test: /\.(png|jpg)$/, loaders: [ 'url?limit=8192' ], exclude: /node_modules/ }
]

var cssLoader = opts.minimize ? 'css-loader' : 'css-loader?localIdentName=[path][name]---[local]---[hash:base64:5]';

var stylesheetLoaders = {
'css': cssLoader,
'less': [ cssLoader, 'less-loader' ],
'styl': [ cssLoader, 'stylus-loader' ],
'scss|sass': [ cssLoader, 'sass-loader' ]
}

var additionalLoaders = [
// { test: /some-reg-exp$/, loader: 'any-loader' }
]

var alias = {

}

var aliasLoader = {

}

var externals = [

]

var modulesDirectories = [ 'node_modules' ]

var extensions = ['', '.web.js', '.js', '.jsx'];

var root = path.join(__dirname, 'app')

var publicPath = opts.devServer
? 'http://localhost:2992/_assets/'
: '/_assets/'


var output = {
path: __dirname + '/public/js/',
filename: 'bundle.js',
publicPath: 'http://localhost:2992/',
contentBase: __dirname + '/public/'
}

var excludeFromStats = [
/node_modules[\\\/]react(-router)?[\\\/]/
]


var plugins = [
new webpack.HotModuleReplacementPlugin()
]

if (opts.prerender) {
plugins.push(new StatsPlugin(path.join(__dirname, 'build', 'stats.prerender.json'), {
chunkModules: true,
exclude: excludeFromStats
}));
aliasLoader['react-proxy$'] = 'react-proxy/unavailable';
aliasLoader['react-proxy-loader$'] = 'react-proxy-loader/unavailable';
externals.push(
/^react(\/.*)?$/,
/^reflux(\/.*)?$/,
'superagent',
'async'
);
plugins.push(new webpack.optimize.LimitChunkCountPlugin({ maxChunks: 1 }));
} else {
plugins.push(new StatsPlugin(path.join(__dirname, 'build', 'stats.json'), {
chunkModules: true,
exclude: excludeFromStats
}));
}

if (opts.commonsChunk) {
plugins.push(new webpack.optimize.CommonsChunkPlugin('commons', 'commons.js' + (opts.longTermCaching && !opts.prerender ? '?[chunkhash]' : '')))
}

// var asyncLoader = {
// test: require('./app/route-handlers/async').map(function(name) {
// return path.join(__dirname, 'app', 'route-handlers', name);
// }),
// loader: opts.prerender ? 'react-proxy-loader/unavailable' : 'react-proxy-loader'
// };

Object.keys(stylesheetLoaders).forEach(function(ext) {
var stylesheetLoader = stylesheetLoaders[ext];
if(Array.isArray(stylesheetLoader)) stylesheetLoader = stylesheetLoader.join('!');
if (opts.prerender) {
stylesheetLoaders[ext] = stylesheetLoader.replace(/^css-loader/, 'css-loader/locals');
} else if (opts.separateStylesheet) {
stylesheetLoaders[ext] = ExtractTextPlugin.extract('style-loader', stylesheetLoader);
} else {
stylesheetLoaders[ext] = 'style-loader!' + stylesheetLoader;
}
})

if (opts.separateStylesheet && !opts.prerender) {
plugins.push(new ExtractTextPlugin('[name].css' + (opts.longTermCaching ? '?[contenthash]' : '')));
}

if(opts.minimize && !opts.prerender) {
plugins.push(
new webpack.optimize.UglifyJsPlugin({
compressor: {
warnings: false
}
}),
new webpack.optimize.DedupePlugin()
)
}

if (opts.minimize) {
plugins.push(
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify('production')
}
}),
new webpack.NoErrorsPlugin()
)
}

return {
entry: entry,
output: output,
target: opts.prerender ? 'node' : 'web',
module: {
loaders: [].concat(loadersByExtension(loaders)).concat(loadersByExtension(stylesheetLoaders)).concat(additionalLoaders)
},
devtool: opts.devtool,
debug: opts.debug,
resolve: {
root: root,
modulesDirectories: modulesDirectories,
extensions: extensions,
alias: alias
},
plugins: plugins,
devServer: {
stats: {
cached: false,
exclude: excludeFromStats
}
}
}
}
42 changes: 42 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"name": "electron-react-boilerplate",
"version": "0.1.0",
"description": "electron-react-boilerplate",
"main": "main.js",
"scripts": {
"test": "mocha",
"dev-server": "webpack-dev-server --config webpack-dev-server.config.js --progress --colors --port 2992 --inline",
"hot-dev-server": "webpack-dev-server --config webpack-hot-dev-server.config.js --hot --progress --colors --port 2992 --inline",
"build": "webpack --config webpack-production.config.js --progress --profile --colors",
"start-dev": "/Applications/Electron.app/Contents/MacOS/Electron .",
"start": "/Applications/Electron.app/Contents/MacOS/Electron ."
},
"repository": {
"type": "git",
"url": "git+https://github.com/chentsulin/electron-react-boilerplate.git"
},
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/chentsulin/electron-react-boilerplate/issues"
},
"homepage": "https://github.com/chentsulin/electron-react-boilerplate#readme",
"devDependencies": {
"babel-loader": "^5.1.2",
"chai": "^2.3.0",
"css-loader": "^0.12.1",
"extract-text-webpack-plugin": "^0.8.0",
"mocha": "^2.2.5",
"proxyquire": "^1.4.0",
"sinon": "^1.14.1",
"stats-webpack-plugin": "^0.1.0",
"style-loader": "^0.12.2",
"webpack": "^1.9.7",
"webpack-dev-server": "^1.8.2"
},
"dependencies": {
"flux": "^2.0.3",
"react": "^0.13.3",
"react-router": "^0.13.3"
}
}
7 changes: 7 additions & 0 deletions test/example.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
var chai = require('chai')

describe('description', function () {
it('description', function () {
// body...
})
})
5 changes: 5 additions & 0 deletions webpack-dev-server.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = require('./make-webpack-config')({
devServer: true,
devtool: 'eval',
debug: true
})
6 changes: 6 additions & 0 deletions webpack-hot-dev-server.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = require('./make-webpack-config')({
devServer: true,
hotComponents: true,
devtool: 'eval',
debug: true
})
Loading

0 comments on commit 9d7637e

Please sign in to comment.