Skip to content

Commit

Permalink
Cleanup node package require for webpackConfigLoader
Browse files Browse the repository at this point in the history
  • Loading branch information
justin808 committed Apr 27, 2017
1 parent 144d3e2 commit e9d4cce
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
const webpack = require('webpack');
const { resolve } = require('path');
const ManifestPlugin = require('webpack-manifest-plugin');
const webpackConfigLoader = require('react-on-rails').default.webpackConfigLoader; // eslint-disable-line import/no-unresolved

const { env, paths, publicPath } = webpackConfigLoader(resolve('..', 'config', 'webpack'));
const webpackConfigLoader = require('react-on-rails/node_package/lib/webpackConfigLoader').default;
const configPath = resolve('..', 'config', 'webpack');
const { env, paths, publicPath } = webpackConfigLoader(configPath);

const devBuild = env !== 'production';

Expand Down
5 changes: 0 additions & 5 deletions node_package/src/ReactOnRails.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import serverRenderReactComponent from './serverRenderReactComponent';
import buildConsoleReplay from './buildConsoleReplay';
import createReactElement from './createReactElement';
import Authenticity from './Authenticity';
import webpackConfigLoader from './webpackConfigLoader';
import context from './context';

const ctx = context();
Expand Down Expand Up @@ -223,10 +222,6 @@ ctx.ReactOnRails = {
resetOptions() {
this.options = Object.assign({}, DEFAULT_OPTIONS);
},

webpackConfigLoader(configPath) {
return webpackConfigLoader.configLoader(configPath);
},
};

ctx.ReactOnRails.resetOptions();
Expand Down
36 changes: 18 additions & 18 deletions node_package/src/webpackConfigLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,26 @@ const { env } = require('process');
const { safeLoad } = require('js-yaml');
const { readFileSync } = require('fs');

export default {
configLoader(configPath) {
const paths = safeLoad(readFileSync(join(configPath, 'paths.yml'), 'utf8'))[env.NODE_ENV];
const configLoader = (configPath) => {
const paths = safeLoad(readFileSync(join(configPath, 'paths.yml'), 'utf8'))[env.NODE_ENV];

const devServerConfig = join(configPath, 'development.server.yml');
const devServer = safeLoad(readFileSync(devServerConfig, 'utf8')).development;
const devServerConfig = join(configPath, 'development.server.yml');
const devServer = safeLoad(readFileSync(devServerConfig, 'utf8')).development;

if (env.REACT_ON_RAILS_ENV === 'HOT') {
devServer.enabled = true;
}
const productionBuild = env.NODE_ENV === 'production';
if (env.REACT_ON_RAILS_ENV === 'HOT') {
devServer.enabled = true;
}
const productionBuild = env.NODE_ENV === 'production';

const publicPath = !productionBuild && devServer.enabled ?
`http://${devServer.host}:${devServer.port}/` : `/${paths.assets}/`;
const publicPath = !productionBuild && devServer.enabled ?
`http://${devServer.host}:${devServer.port}/` : `/${paths.assets}/`;

return {
devServer,
env,
paths,
publicPath,
};
},
return {
devServer,
env,
paths,
publicPath,
};
};

export default configLoader;
5 changes: 3 additions & 2 deletions spec/dummy/client/server-rails-hot.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ import WebpackDevServer from 'webpack-dev-server';
const { resolve } = require('path');
import webpackConfig from './webpack.client.rails.hot.config';

const webpackConfigLoader = require('react-on-rails').default.webpackConfigLoader;
const { devServer: devServerConfig, publicPath } = webpackConfigLoader(resolve('..', 'config', 'webpack'));
const webpackConfigLoader = require('react-on-rails/node_package/lib/webpackConfigLoader').default;
const configPath = resolve('..', 'config', 'webpack');
const { devServer: devServerConfig, publicPath } = webpackConfigLoader(configPath);

const compiler = webpack(webpackConfig);

Expand Down
5 changes: 3 additions & 2 deletions spec/dummy/client/webpack.client.base.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ const webpackCommon = require('./webpack.common');
const { assetLoaderRules } = webpackCommon;

const ManifestPlugin = require('webpack-manifest-plugin');
const webpackConfigLoader = require('react-on-rails').default.webpackConfigLoader;
const { env, paths, publicPath } = webpackConfigLoader(resolve('..', 'config', 'webpack'));
const webpackConfigLoader = require('react-on-rails/node_package/lib/webpackConfigLoader').default;
const configPath = resolve('..', 'config', 'webpack');
const { paths, publicPath } = webpackConfigLoader(configPath);

const devBuild = process.env.NODE_ENV !== 'production';

Expand Down
5 changes: 3 additions & 2 deletions spec/dummy/client/webpack.client.rails.build.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const config = require('./webpack.client.base.config');
const { resolve } = require('path');
const webpackConfigLoader = require('react-on-rails').default.webpackConfigLoader;
const { env, paths, publicPath } = webpackConfigLoader(resolve('..', 'config', 'webpack'));
const webpackConfigLoader = require('react-on-rails/node_package/lib/webpackConfigLoader').default;
const configPath = resolve('..', 'config', 'webpack');
const { paths, publicPath } = webpackConfigLoader(configPath);

const devBuild = process.env.NODE_ENV !== 'production';

Expand Down
5 changes: 3 additions & 2 deletions spec/dummy/client/webpack.client.rails.hot.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ const { resolve } = require('path');
const webpack = require('webpack');

const config = require('./webpack.client.base.config');
const webpackConfigLoader = require('react-on-rails').default.webpackConfigLoader;
const { devServer, paths, publicPath } = webpackConfigLoader(resolve('..', 'config', 'webpack'));
const webpackConfigLoader = require('react-on-rails/node_package/lib/webpackConfigLoader').default;
const configPath = resolve('..', 'config', 'webpack');
const { devServer, paths, publicPath } = webpackConfigLoader(configPath);

config.entry.app.push(
`webpack-dev-server/client?${devServer.host}:${devServer.port}`,
Expand Down
6 changes: 3 additions & 3 deletions spec/dummy/client/webpack.server.rails.build.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@

const webpack = require('webpack');
const { resolve, join } = require('path');
const { imageLoaderRules } = require('./webpack.common');
const webpackCommon = require('./webpack.common');
const { assetLoaderRules } = webpackCommon;

const webpackConfigLoader = require('react-on-rails').default.webpackConfigLoader;
const { env, paths, publicPath } = webpackConfigLoader(resolve('..', 'config', 'webpack'));
const webpackConfigLoader = require('react-on-rails/node_package/lib/webpackConfigLoader').default;
const configPath = resolve('..', 'config', 'webpack');
const { paths } = webpackConfigLoader(configPath);

const devBuild = process.env.NODE_ENV !== 'production';
const nodeEnv = devBuild ? 'development' : 'production';
Expand Down
4 changes: 2 additions & 2 deletions spec/dummy/client/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4177,8 +4177,8 @@ react-helmet@^5.0.3:
prop-types "^15.5.4"
react-side-effect "^1.1.0"

"react-on-rails@file:../../..":
version "6.10.1"
"react-on-rails@file:../../../":
version "7.0.0"

react-proptypes@^0.0.1:
version "0.0.1"
Expand Down

0 comments on commit e9d4cce

Please sign in to comment.