Skip to content

Commit

Permalink
Setup production build and server
Browse files Browse the repository at this point in the history
  • Loading branch information
ArifaMujawar committed Jan 5, 2020
1 parent f4f41b6 commit bb80717
Show file tree
Hide file tree
Showing 8 changed files with 268 additions and 477 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
node_modules
node_modules/
public/bundle.js
public/bundle.js.map
public/styles.css
public/styles.css.map
9 changes: 7 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@
"license": "MIT",
"scripts": {
"serve": "live-server public/",
"build": "webpack",
"build:dev": "webpack",
"build:prod": "webpack -p --env production",
"dev-server": "webpack-dev-server",
"test": "jest --config=jest.config.json"
"test": "jest --config=jest.config.json",
"start" : "node server/server.js",
"heroku-postbuild":"yarn run build:prod"
},
"dependencies": {
"babel-cli": "6.24.1",
Expand All @@ -19,6 +22,8 @@
"css-loader": "0.28.4",
"enzyme-adapter-react-16": "1.0.0",
"enzyme-to-json": "3.0.1",
"express": "4.15.4",
"extract-text-webpack-plugin": "3.0.0",
"jest": "20.0.4",
"live-server": "^1.2.1",
"moment": "2.18.1",
Expand Down
471 changes: 36 additions & 435 deletions public/bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Expensify App</title>
<link rel= "icon" type="image/png" href="/images/favicon.png" />

<link rel ="stylesheet" type="text/css" href ="/styles.css" />
</head>
<body>
<div id="app"></div>
Expand Down
15 changes: 15 additions & 0 deletions server/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const path = require('path');
const express = require('express');
const app = express();
const publicPath = path.join(__dirname, '..', 'public');
const port = process.env.PORT || 3000;

app.use(express.static(publicPath));

app.get('*',(req, res) => {
res.sendFile(path.join(publicPath, 'index.html'));
});

app.listen(port, ()=>{
console.log('Server is up!');
});
2 changes: 1 addition & 1 deletion src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ store.dispatch(addExpense({description:'milk', amount :9000, createdAt:300}));

const state = store.getState();
const visibleExpenses = getVisibleExpenses(state.expenses, state.filters);
console.log(visibleExpenses);
console.log('visibleExpenses tetsing');

const jsx = (
<Provider store = {store}>
Expand Down
72 changes: 46 additions & 26 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,49 @@
const path = require('path');
const ExtractTextPlugin = require('extract-text-webpack-plugin');

module.exports = {
entry: './src/app.js',
output: {
path:path.join(__dirname,'public'),
filename:'bundle.js'
},
module:{
rules:[{
loader: 'babel-loader',
test: /\.js$/,
exclude:/node_modules/
},{
test: /\.s?css$/,
use: [
'style-loader',
'css-loader',
'sass-loader'
]
module.exports = (env) => {
const isProduction = env === 'production';
const CSSExtract = new ExtractTextPlugin('styles.css');
console.log('env:',env);
return {
entry: './src/app.js',
output: {
path:path.join(__dirname,'public'),
filename:'bundle.js'
},
module:{
rules:[{
loader: 'babel-loader',
test: /\.js$/,
exclude:/node_modules/
},{
test: /\.s?css$/,
use: CSSExtract.extract({
use: [
{
loader: 'css-loader',
options: {
sourceMap: true
}
},
{
loader: 'sass-loader',
options: {
sourceMap: true
}
}
]
})
}
]
},
plugins: [
CSSExtract
],
devtool: isProduction?'source-map':'inline-source-map',
devServer: {
contentBase: path.join(__dirname,'public'),
historyApiFallback:true
}
]
},
devtool: 'cheap-module-eval-source-map',
devServer: {
contentBase: path.join(__dirname,'public'),
historyApiFallback:true
}
};
};
};
Loading

0 comments on commit bb80717

Please sign in to comment.