Skip to content

Commit

Permalink
simplify webpack config
Browse files Browse the repository at this point in the history
  • Loading branch information
chentsulin committed Oct 11, 2015
1 parent b2ddeb2 commit f79b70b
Show file tree
Hide file tree
Showing 18 changed files with 183 additions and 224 deletions.
3 changes: 2 additions & 1 deletion app/app.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
<head>
<meta charset="utf-8">
<title>Hello Electron React!</title>
<link rel="stylesheet" href="../dist/main.css" />
<link rel="stylesheet" href="../dist/global-style.css" />
<link rel="stylesheet" href="../dist/style.css" />
</head>
<body>
<div id="react-root"></div>
Expand Down
2 changes: 1 addition & 1 deletion app/hot-dev-app.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
</head>
<body>
<div id="react-root"></div>
<script src="http://localhost:2992/dist/bundle.js"></script>
<script src="http://localhost:3000/dist/bundle.js"></script>
</body>
</html>
2 changes: 0 additions & 2 deletions dist/.gitignore

This file was deleted.

26 changes: 26 additions & 0 deletions dist/bundle.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dist/bundle.js.map

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions dist/global-style.css

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

1 change: 1 addition & 0 deletions dist/global-style.css.map

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

2 changes: 1 addition & 1 deletion package.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint no-shadow: 0, func-names: 0, no-unused-vars: 0, no-console: 0 */
var os = require('os');
var webpack = require('webpack');
var cfg = require('./webpack/webpack.config.production.js');
var cfg = require('./webpack.config.production.js');
var packager = require('electron-packager');
var assign = require('object-assign');
var del = require('del');
Expand Down
12 changes: 2 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@
"scripts": {
"test": "mocha",
"lint": "eslint .",
"dev-server": "webpack-dev-server --config webpack/webpack-dev-server.config.js --progress --colors --port 2992 --inline",
"hot-dev-server": "webpack-dev-server --config webpack/webpack-hot-dev-server.config.js --hot --progress --colors --port 2992 --inline",
"build": "webpack --config webpack/webpack.config.production.js --progress --profile --colors",
"hot-server": "node server.js",
"build": "webpack --config webpack.config.production.js --progress --profile --colors",
"start": "electron .",
"start-dev": "NODE_ENV=development electron .",
"start-hot": "HOT=1 NODE_ENV=development electron .",
"package": "node package.js",
"package-all": "node package.js --all"
Expand Down Expand Up @@ -56,11 +54,6 @@
"eslint-config-airbnb": "0.0.8",
"eslint-plugin-react": "^3.3.1",
"extract-text-webpack-plugin": "^0.8.2",
"file-loader": "^0.8.4",
"html-loader": "^0.3.0",
"json-loader": "^0.5.2",
"loaders-by-extension": "^1.0.0",
"markdown-loader": "^0.1.7",
"minimist": "^1.2.0",
"mocha": "^2.3.0",
"node-libs-browser": ">= 0.4.0 <=0.6.0",
Expand All @@ -71,7 +64,6 @@
"sinon": "^1.16.1",
"stats-webpack-plugin": "^0.2.1",
"style-loader": "^0.12.3",
"url-loader": "^0.5.6",
"webpack": "^1.12.1",
"webpack-dev-server": "^1.10.1",
"webpack-target-electron-renderer": "^0.1.0"
Expand Down
18 changes: 18 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
var webpack = require('webpack');
var WebpackDevServer = require('webpack-dev-server');
var config = require('./webpack.config.development');

new WebpackDevServer(webpack(config), {
publicPath: config.output.publicPath,
hot: true,
historyApiFallback: true,
stats: {
colors: true
}
}).listen(3000, 'localhost', function(err) {
if (err) {
console.log(err);
}

console.log('Listening at localhost:3000');
});
20 changes: 20 additions & 0 deletions webpack.config.base.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module.exports = {
module: {
loaders: []
},
output: {
path: './dist/',
filename: 'bundle.js',
libraryTarget: 'commonjs2'
},
resolve: {
extensions: ['', '.js', '.jsx'],
packageMains: ['webpack', 'browser', 'web', 'browserify', ['jam', 'main'], 'main']
},
plugins: [

],
externals: [
// put your node 3rd party libraries which can't be built with webpack here (mysql, mongodb, and so on..)
]
};
52 changes: 52 additions & 0 deletions webpack.config.development.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/* eslint strict: 0 */
'use strict';

var webpack = require('webpack');
var webpackTargetElectronRenderer = require('webpack-target-electron-renderer');
var baseConfig = require('./webpack.config.base');


var config = Object.create(baseConfig);

config.debug = true;

config.devtool = 'cheap-module-eval-source-map';

config.entry = [
'webpack-dev-server/client?http://localhost:3000',
'webpack/hot/only-dev-server',
'./app/mainApp'
];

config.output.publicPath = 'http://localhost:3000/dist/';

config.module.loaders.push({
test: /\.jsx?$/,
loaders: ['react-hot-loader', 'babel-loader'],
exclude: /node_modules/
}, {
test: /^((?!\.module).)*\.css$/,
loaders: [
'style-loader',
'css-loader'
]
}, {
test: /\.module\.css$/,
loaders: [
'style-loader',
'css-loader?modules&importLoaders=1&localIdentName=[name]__[local]___[hash:base64:5]!'
]
});


config.plugins.push(
new webpack.HotModuleReplacementPlugin(),
new webpack.DefinePlugin({
'__DEV__': true,
'process.env': JSON.stringify('development')
})
);

config.target = webpackTargetElectronRenderer(config);

module.exports = config;
57 changes: 57 additions & 0 deletions webpack.config.production.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/* eslint strict: 0 */
'use strict';

var webpack = require('webpack');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var webpackTargetElectronRenderer = require('webpack-target-electron-renderer');
var baseConfig = require('./webpack.config.base');


var config = Object.create(baseConfig);

config.devtool = 'source-map';

config.entry = './app/mainApp';

config.output.publicPath = '/dist/';

var stylesTextPlugin = new ExtractTextPlugin('style.css', { allChunks: true });
var globalStylesTextPlugin = new ExtractTextPlugin('global-style.css', { allChunks: true });

config.module.loaders.push({
test: /\.jsx?$/,
loaders: ['babel-loader'],
exclude: /node_modules/
}, {
test: /^((?!\.module).)*\.css$/,
loader: globalStylesTextPlugin.extract(
'style-loader',
'css-loader'
)
}, {
test: /\.module\.css$/,
loader: stylesTextPlugin.extract(
'style-loader',
'css-loader?modules&importLoaders=1&localIdentName=[name]__[local]___[hash:base64:5]'
)
});

config.plugins.push(
new webpack.optimize.OccurenceOrderPlugin(),
new webpack.DefinePlugin({
'__DEV__': false,
'process.env': JSON.stringify('production')

This comment has been minimized.

Copy link
@vramana

vramana Nov 16, 2015

Contributor

@chentsulin Shouldn't this be process.env.NODE_ENV ? When I packaged the application using the latest version of package, redux devtools was getting bundled in the package.

This comment has been minimized.

Copy link
@chentsulin

chentsulin Nov 16, 2015

Author Member

@vramana it should be:

'process.env': {
  'NODE_ENV': JSON.stringify('production')
}

Would you make a PR to fix this?

This comment has been minimized.

Copy link
@vramana

vramana Nov 16, 2015

Contributor

Sure.

@chentsulin Does this work http://electron.atom.io/docs/v0.34.0/tutorial/devtools-extension/ ?? For attaching React Devtools. I am running into few issues.

Here is what I wrote inside hot-dev-app.html

var remote = require('remote');
remote.getCurrentWindow().addDevToolsExtension('/tools/react-devtools/shells/chrome');

The console gives the error addDevToolsExtension is not a function.

This comment has been minimized.

Copy link
@chentsulin

chentsulin Nov 16, 2015

Author Member

It's not working now, see:
electron/electron#915

}),
new webpack.optimize.UglifyJsPlugin({
compressor: {
screw_ie8: true,
warnings: false
}
}),
stylesTextPlugin,
globalStylesTextPlugin
);

config.target = webpackTargetElectronRenderer(config);

module.exports = config;
Loading

0 comments on commit f79b70b

Please sign in to comment.