Skip to content
This repository has been archived by the owner on Oct 26, 2021. It is now read-only.

Commit

Permalink
Merge branch 'master' of github.com:bdefore/universal-redux into feat…
Browse files Browse the repository at this point in the history
…ure/koa-support

# Conflicts:
#	config/universal-redux.config.js
#	src/index.js
#	src/server/renderer.js
  • Loading branch information
Bartol Karuza committed Feb 10, 2016
2 parents 7f41301 + 6fa6dea commit 7023b42
Show file tree
Hide file tree
Showing 22 changed files with 741 additions and 284 deletions.
9 changes: 5 additions & 4 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,14 @@
}
},
"globals": {
"__DEVELOPMENT__": true,
"__CLIENT__": true,
"__SERVER__": true,
"__LOGGER__": false,
"__DISABLE_SSR__": true,
"__DEVELOPMENT__": true,
"__DEVTOOLS__": true,
"__DEVTOOLS_IS_VISIBLE__": true,
"__DISABLE_SSR__": true,
"__LOGGER__": false,
"__PROVIDERS__": [],
"__SERVER__": true,
"webpackIsomorphicTools": true
}
}
67 changes: 30 additions & 37 deletions bin/merge-configs.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
#!/usr/bin/env node
const path = require('path');
const util = require('util');

const lodash = require('lodash');
const webpack = require('webpack');
const mergeBabel = require('./merge-babel-config');
const mergeWebpack = require('webpack-config-merger');
const baseWebpackConfig = require('../config/webpack.config.js');
const baseDevConfig = mergeWebpack(baseWebpackConfig.common, baseWebpackConfig.development);
const baseProdConfig = mergeWebpack(baseWebpackConfig.common, baseWebpackConfig.production);
const baseToolsConfig = require('../config/webpack-isomorphic-tools.config.js');
const WebpackIsomorphicToolsPlugin = require('webpack-isomorphic-tools/plugin');
const WebpackErrorNotificationPlugin = require('webpack-error-notification');

const mergeBabel = require('./merge-babel-config');
const baseConfig = require('../config/universal-redux.config.js');
const webpackConfigs = require('../config/webpack.config.js');
const baseToolsConfig = require('../config/webpack-isomorphic-tools.config.js');

const isProduction = process.env.NODE_ENV === 'production';

function inspect(obj) {
Expand All @@ -24,18 +24,18 @@ function inspect(obj) {
}

module.exports = (userConfig) => {
// derive root and sourceDir, alowing for absolute, relative, or not provided
const root = userConfig.root ? userConfig.root[0] === '/' ? userConfig.root : path.resolve(__dirname, '../..', userConfig.root) : path.resolve(__dirname, '../../..');
const sourceDir = userConfig.sourceDir ? userConfig.sourceDir[0] === '/' ? userConfig.sourceDir : path.resolve(root, userConfig.sourceDir) : path.resolve(root, './src');
const projectRoot = process.cwd();
const sourceRoot = `${projectRoot}/src`;

// merge with base config
const universalReduxConfig = lodash.merge(require('../config/universal-redux.config.js')(root, sourceDir), userConfig);
const universalReduxConfig = lodash.merge(baseConfig, userConfig);

// merge with base webpack config
const baseConfig = isProduction ? baseProdConfig : baseDevConfig;
const combinedWebpackConfig = mergeWebpack(baseConfig, universalReduxConfig.webpack.config);
combinedWebpackConfig.context = root;
combinedWebpackConfig.resolve.root = sourceDir;
const webpackSubset = isProduction ? webpackConfigs.production : webpackConfigs.development;
const baseWebpackConfig = mergeWebpack(webpackConfigs.common, webpackSubset);
const combinedWebpackConfig = mergeWebpack(baseWebpackConfig, universalReduxConfig.webpack.config);
combinedWebpackConfig.context = projectRoot;
combinedWebpackConfig.resolve.root = sourceRoot;

// derive webpack output destination from staticPath
combinedWebpackConfig.output.path = universalReduxConfig.server.staticPath + '/dist';
Expand All @@ -52,7 +52,6 @@ module.exports = (userConfig) => {
combinedToolsConfig.webpack_assets_file_path = 'node_modules/universal-redux/webpack-assets.json';

// add tools settings to combined weback config
const WebpackIsomorphicToolsPlugin = require('webpack-isomorphic-tools/plugin');
const toolsPlugin = new WebpackIsomorphicToolsPlugin(combinedToolsConfig);

combinedWebpackConfig.module.loaders.push({ test: toolsPlugin.regular_expression('images'), loader: 'url-loader?limit=10240' });
Expand All @@ -72,30 +71,12 @@ module.exports = (userConfig) => {
combinedWebpackConfig.plugins.push(new WebpackErrorNotificationPlugin());
}

// add default settings that are used by server via process.env
const definitions = {
__LOGGER__: false,
__DEVTOOLS__: !isProduction,
__DEVELOPMENT__: !isProduction
};

// override with user settings
lodash.each(universalReduxConfig.globals, (value, key) => { definitions[key] = JSON.stringify(value); });
combinedWebpackConfig.plugins.push(new webpack.DefinePlugin(definitions));

// add routes, reducer and rootComponent aliases so that client has access to them
// add routes, reducer and rootClientComponent aliases so that client has access to them
combinedWebpackConfig.resolve.alias = combinedWebpackConfig.resolve.alias || {};
combinedWebpackConfig.resolve.alias.routes = universalReduxConfig.routes;
if (universalReduxConfig.redux.middleware) {
combinedWebpackConfig.resolve.alias.middleware = universalReduxConfig.redux.middleware;
} else {
combinedWebpackConfig.resolve.alias.middleware = path.resolve(__dirname, '../lib/helpers/empty.js');
}
if (universalReduxConfig.rootComponent) {
combinedWebpackConfig.resolve.alias.rootComponent = universalReduxConfig.rootComponent;
} else {
combinedWebpackConfig.resolve.alias.rootComponent = path.resolve(__dirname, '../lib/helpers/rootComponent.js');
}
combinedWebpackConfig.resolve.alias.middleware = universalReduxConfig.redux.middleware || path.resolve(__dirname, '../lib/helpers/empty.js');
const rootComponentPath = universalReduxConfig.rootClientComponent || universalReduxConfig.rootComponent || path.resolve(__dirname, '../lib/client/root.js');
combinedWebpackConfig.resolve.alias.rootClientComponent = rootComponentPath;

// add project level vendor libs
if (universalReduxConfig.webpack.vendorLibraries && isProduction) {
Expand All @@ -104,6 +85,18 @@ module.exports = (userConfig) => {
});
}

// add default settings that are used by server via process.env
const definitions = {
__DEVTOOLS__: !isProduction,
__DEVELOPMENT__: !isProduction,
__LOGGER__: false,
__PROVIDERS__: JSON.stringify(universalReduxConfig.providers)
};

// override with user settings
lodash.each(universalReduxConfig.globals, (value, key) => { definitions[key] = JSON.stringify(value); });
combinedWebpackConfig.plugins.push(new webpack.DefinePlugin(definitions));

// output configuration files if user wants verbosity
if (universalReduxConfig.verbose) {
console.log('\nWebpack config:');
Expand Down
4 changes: 3 additions & 1 deletion bin/user-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ const userConfigPath = path.join(process.cwd(), './config/universal-redux.config
function getConfig() {
try {
const config = require(path.resolve(userConfigPath));
console.log('Loaded project level config', config);
if (config.verbose) {
console.log(`Loaded project level config from ${userConfigPath}`);
}
return config;
} catch (err) {
console.error('No configuration file provided, using defaults.', err);
Expand Down
Loading

0 comments on commit 7023b42

Please sign in to comment.