Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed webpack setup to seperate compilated client and server code #95

Merged
merged 4 commits into from
Jul 1, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"build-server": "cross-env NODE_ENV=production ./node_modules/.bin/babel ./server --out-dir ./build",
"lint": "eslint client server",
"flow": "flow",
"heroku-postbuild": "cross-env NODE_ENV=production webpack --config webpack.config.js && cross-env NODE_ENV=production ./node_modules/.bin/babel ./server --out-dir ./lib",
"heroku-postbuild": "cross-env NODE_ENV=production webpack --config webpack.config.js && cross-env NODE_ENV=production ./node_modules/.bin/babel ./server --out-dir ./build",
Copy link
Owner

@lvarayut lvarayut Jun 30, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to change the output path of the Heroku app?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. This is not necessary.

"clean": "rm -rf build && mkdir build",
"relay": "relay-compiler --src ./client --schema server/data/schema.graphql"
},
Expand Down Expand Up @@ -97,7 +97,7 @@
"react-router-relay": "^0.14.0",
"style-loader": "^0.18.2",
"url-loader": "^0.5.9",
"webpack": "^3.0.0",
"webpack": "2",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you explain why do you downgrade the version of webpack?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I couldn't start with webpack 3. Doesn't have anything to do with this issue though.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jkettmann Also having trouble starting new webpack 3 something along these lines?

ERROR in   TypeError: Cannot read property 'request' of undefined
  
  - ExternalModuleFactoryPlugin.js:37 handleExternals
    [relay-fullstack]/[html-webpack-plugin]/[webpack]/lib/ExternalModuleFactoryP    lugin.js:37:33
  
....

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ncrmro and @jkettmann, those are very useful information

"webpack-dev-server": "2.5.0"
}
}
2 changes: 1 addition & 1 deletion server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ if (config.env === 'development') {
// Launch Relay by creating a normal express server
const relayServer = express();
relayServer.use(historyApiFallback());
relayServer.use('/', express.static(path.join(__dirname, '../build')));
relayServer.use('/', express.static(path.join(__dirname, '../build/app')));
relayServer.use('/graphql', graphQLHTTP({ schema }));
relayServer.listen(config.port, () => console.log(chalk.green(`Relay is listening on port ${config.port}`)));
}
5 changes: 4 additions & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const FaviconsWebpackPlugin = require('favicons-webpack-plugin');

let outputPath;
let appEntry;
let devtool;
let plugins;

if (process.env.NODE_ENV === 'production') {
appEntry = [path.join(__dirname, 'client/index.js')];
outputPath = path.join(__dirname, 'build/app');
devtool = 'source-map';
plugins = [
new webpack.optimize.OccurrenceOrderPlugin(),
Expand Down Expand Up @@ -41,6 +43,7 @@ if (process.env.NODE_ENV === 'production') {
'webpack-dev-server/client?http://localhost:3000',
'webpack/hot/only-dev-server'
];
outputPath = path.join(__dirname, 'app');
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to use the different path for the development environment?

Copy link
Contributor Author

@jkettmann jkettmann Jun 30, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right again. Is the contentBase and static server in server/index.js necessary (if I remove them everything seems to be still working). I guess that's why I used a different path for development.

const relayServer = new WebpackDevServer(webpack(webpackConfig), {
    contentBase: '/build/',

...

relayServer.use('/', express.static(path.join(__dirname, '../build/app')));

devtool = 'eval';
plugins = [
new webpack.optimize.CommonsChunkPlugin({ name: 'vendor', filename: 'vendor.js' }),
Expand All @@ -66,7 +69,7 @@ module.exports = {
vendor: ['react', 'react-dom', 'react-mdl', 'react-relay', 'react-router', 'react-router-relay']
},
output: {
path: path.join(__dirname, 'build'),
path: outputPath,
publicPath: '/',
filename: '[name].js'
},
Expand Down