Skip to content

Commit

Permalink
refactor(config): extract webpack/build config into hops-build-config
Browse files Browse the repository at this point in the history
Move all build-relevant config into a new package "hops-build-config",
to free "hops-config" from all dependencies that are only relevant for
building code (webpack, babel, postcss, etc).
Now hops-config only contains the base configuration of paths etc and
hops-build-config contains all devDependencies.

THIS IS A BREAKING CHANGE:
`buildConfig`, `developConfig` and `nodeConfig` have been removed from
`hops-config`.
They are now accessible on the `hops-build-config` export.
Also: All deep-requires into `hops-config/{configs,lib/check-esnext,
loaders,plugins,sections,shims,ssl}` must now use `hops-build-config`.
  • Loading branch information
ZauberNerd authored and dmbch committed Oct 13, 2017
1 parent f7a245f commit dbeeb5a
Show file tree
Hide file tree
Showing 40 changed files with 133 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ var MinifyPlugin = require('babel-minify-webpack-plugin');
var WriteManifestPlugin = require('../plugins/write-manifest');
var WriteFilePlugin = require('../plugins/write-file');

var hopsConfig = require('..');
var hopsConfig = require('hops-config');

var getAssetPath = path.join.bind(path, hopsConfig.assetPath);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ var webpack = require('webpack');

var WriteManifestPlugin = require('../plugins/write-manifest');

var hopsConfig = require('..');
var hopsConfig = require('hops-config');

var getAssetPath = path.join.bind(path, hopsConfig.assetPath);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
var path = require('path');
var webpack = require('webpack');

var hopsConfig = require('..');
var hopsConfig = require('hops-config');

var hopsConfigInstallDir = path.dirname(require.resolve('hops-config'));
var modulesDir = path.resolve(hopsConfigInstallDir, '..');
Expand Down
29 changes: 29 additions & 0 deletions packages/build-config/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
'use strict';

var hopsConfig = require('hops-config');

function freeze (config) {
return Object.freeze(
Object.keys(config).reduce(function (result, key) {
var descriptor = { enumerable: true };
if (typeof config[key] === 'function') {
descriptor.get = config[key];
} else {
descriptor.value = config[key];
}
return Object.defineProperty(result, key, descriptor);
}, {})
);
}

module.exports = freeze({
buildConfig: hopsConfig.buildConfig
? hopsConfig.buildConfig
: require.resolve('./configs/build'),
developConfig: hopsConfig.developConfig
? hopsConfig.developConfig
: require.resolve('./configs/develop'),
nodeConfig: hopsConfig.nodeConfig
? hopsConfig.nodeConfig
: require.resolve('./configs/node')
});
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

var hopsConfig = require('..');
var hopsConfig = require('hops-config');

module.exports = function () {
this.cacheable();
Expand Down
File renamed without changes.
63 changes: 63 additions & 0 deletions packages/build-config/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
"name": "hops-build-config",
"version": "6.2.8",
"description": "Hops core configuration leveraging Webpack and Babel",
"keywords": [
"hops",
"webpack",
"babel",
"postcss"
],
"license": "MIT",
"main": "index.js",
"files": [
"index.js",
"manifest.js",
"configs",
"lib",
"loaders",
"plugins",
"sections",
"shims",
"ssl"
],
"scripts": {
"test": "echo \"Error: run tests in xing/hops repo\" && exit 1"
},
"repository": {
"type": "git",
"url": "https://github.com/xing/hops.git"
},
"dependencies": {
"babel-core": "^6.26.0",
"babel-loader": "^7.1.2",
"babel-minify-webpack-plugin": "0.2.0",
"babel-plugin-dynamic-import-node": "^1.1.0",
"babel-plugin-flow-react-proptypes": "^5.2.0",
"babel-plugin-syntax-dynamic-import": "^6.18.0",
"babel-plugin-transform-class-properties": "^6.24.1",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"babel-polyfill": "^6.26.0",
"babel-preset-env": "^1.6.0",
"babel-preset-react": "^6.24.1",
"css-loader": "^0.28.7",
"extract-text-webpack-plugin": "^3.0.0",
"file-loader": "^0.11.2",
"json-loader": "^0.5.7",
"lodash.template": "^4.4.0",
"mkdirp": "^0.5.1",
"pkg-dir": "^2.0.0",
"postcss": "^6.0.12",
"postcss-cssnext": "^3.0.2",
"postcss-import": "^11.0.0",
"postcss-loader": "^2.0.6",
"style-loader": "^0.18.2",
"url-loader": "^0.5.9",
"webpack": "^3.6.0",
"webpack-dev-server": "^2.9.1",
"webpack-node-externals": "^1.6.0"
},
"peerDependencies": {
"hops-config": "6.2.8"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var fs = require('fs');
var path = require('path');
var mkdirp = require('mkdirp');

var hopsConfig = require('..');
var hopsConfig = require('hops-config');

module.exports = function Plugin (regExp) {
this.apply = function (compiler) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var fs = require('fs');
var path = require('path');
var mkdirp = require('mkdirp');

var hopsConfig = require('..');
var hopsConfig = require('hops-config');

module.exports = function Plugin (regExp) {
this.apply = function (compiler) {
Expand Down
11 changes: 11 additions & 0 deletions packages/build-config/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

# Hops Build Config



### Target Audience



### Example

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
var fs = require('fs');
var path = require('path');

var hopsConfig = require('..');
var hopsConfig = require('hops-config');

function readSSLFile (fileName) {
var filePath = path.resolve(__dirname, '..', 'ssl', fileName);
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

var hopsConfig = require('../..');
var hopsConfig = require('hops-config');

function createIdentifier (targets) {
return JSON.stringify({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

var path = require('path');

var hopsConfig = require('../..');
var hopsConfig = require('hops-config');

exports.default = {
test: /\.(html|svg|((o|t)tf)|woff2?|ico)$/,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

var ExtractTextPlugin = require('extract-text-webpack-plugin');

var hopsConfig = require('../..');
var hopsConfig = require('hops-config');

var cssLoaderOptions = {
importLoaders: 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

var path = require('path');

var hopsConfig = require('../..');
var hopsConfig = require('hops-config');

exports.default = {
test: /\.(png|gif|jpe?g|webp)$/,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

var hopsConfig = require('..');
var hopsConfig = require('hops-config');

module.exports = function getResolveConfig (target) {
var platform = (target === 'node') ? 'server' : 'browser';
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 3 additions & 2 deletions packages/build/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ var webpack = require('webpack');
var merge = require('webpack-merge');

var hopsConfig = require('hops-config');
var hopsBuildConfig = require('hops-build-config');
var HopsPlugin = require('hops-plugin');

var buildConfig = require(hopsConfig.buildConfig);
var nodeConfig = require(hopsConfig.nodeConfig);
var buildConfig = require(hopsBuildConfig.buildConfig);
var nodeConfig = require(hopsBuildConfig.nodeConfig);

var cleanup = require('./lib/cleanup');

Expand Down
1 change: 1 addition & 0 deletions packages/build/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"url": "https://github.com/xing/hops.git"
},
"dependencies": {
"hops-build-config": "6.2.8",
"hops-middleware": "6.2.8",
"hops-plugin": "6.2.8",
"hops-server": "6.2.8",
Expand Down
5 changes: 3 additions & 2 deletions packages/build/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var webpack = require('webpack');
var WebpackServer = require('webpack-dev-server');

var hopsConfig = require('hops-config');
var hopsBuildConfig = require('hops-build-config');
var createMiddleware = require('hops-middleware');
var server = require('hops-server');

Expand All @@ -14,7 +15,7 @@ process.on('unhandledRejection', function (error) {
});

function runDevelop (options, callback) {
var config = require(hopsConfig.developConfig);
var config = require(hopsBuildConfig.developConfig);
var watchOptions = config.devServer.watchOptions || config.watchOptions;
var app = new WebpackServer(
webpack(config),
Expand All @@ -23,7 +24,7 @@ function runDevelop (options, callback) {
app.use(server.rewritePath);
server.bootstrap(app, hopsConfig);
server.registerMiddleware(app, createMiddleware(
require(hopsConfig.nodeConfig),
require(hopsBuildConfig.nodeConfig),
watchOptions
));
server.teardown(app, hopsConfig);
Expand Down
3 changes: 0 additions & 3 deletions packages/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,6 @@ module.exports = freeze(
appDir: '.',
buildDir: 'build',
cacheDir: 'node_modules/.cache/hops',
buildConfig: require.resolve('./configs/build'),
developConfig: require.resolve('./configs/develop'),
nodeConfig: require.resolve('./configs/node'),
manifest: manifestUtil.getManifest,
assets: manifestUtil.getAssets
})
Expand Down
30 changes: 2 additions & 28 deletions packages/config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,32 +29,6 @@
"url": "https://github.com/xing/hops.git"
},
"dependencies": {
"babel-core": "^6.26.0",
"babel-loader": "^7.1.2",
"babel-minify-webpack-plugin": "0.2.0",
"babel-plugin-dynamic-import-node": "^1.1.0",
"babel-plugin-flow-react-proptypes": "^5.2.0",
"babel-plugin-syntax-dynamic-import": "^6.18.0",
"babel-plugin-transform-class-properties": "^6.24.1",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"babel-polyfill": "^6.26.0",
"babel-preset-env": "^1.6.0",
"babel-preset-react": "^6.24.1",
"css-loader": "^0.28.7",
"extract-text-webpack-plugin": "^3.0.0",
"file-loader": "^0.11.2",
"json-loader": "^0.5.7",
"lodash.template": "^4.4.0",
"mkdirp": "^0.5.1",
"pkg-dir": "^2.0.0",
"postcss": "^6.0.12",
"postcss-cssnext": "^3.0.2",
"postcss-import": "^11.0.0",
"postcss-loader": "^2.0.6",
"style-loader": "^0.18.2",
"url-loader": "^0.5.9",
"webpack": "^3.6.0",
"webpack-dev-server": "^2.9.1",
"webpack-node-externals": "^1.6.0"
"pkg-dir": "^2.0.0"
}
}
}
3 changes: 2 additions & 1 deletion packages/express/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ var mime = require('mime');
var helmet = require('helmet');

var hopsConfig = require('hops-config');
var webpackConfig = require(hopsConfig.nodeConfig);
var hopsBuildConfig = require('hops-build-config');
var webpackConfig = require(hopsBuildConfig.nodeConfig);

var server = require('hops-server');

Expand Down
1 change: 1 addition & 0 deletions packages/express/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"dependencies": {
"express": "^4.16.0",
"helmet": "^3.8.2",
"hops-build-config": "6.2.8",
"hops-server": "6.2.8",
"mime": "^2.0.3"
},
Expand Down
4 changes: 2 additions & 2 deletions packages/jest-preset/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"identity-obj-proxy": "^3.0.0"
},
"peerDependencies": {
"hops-config": "6.2.8",
"hops-build-config": "6.2.8",
"jest": "21"
}
}
}
2 changes: 1 addition & 1 deletion packages/jest-preset/transform.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var babelJest = require('babel-jest');

var loaderConfig = require('hops-config/sections/module-rules/babel').node;
var loaderConfig = require('hops-build-config/sections/module-rules/babel').node;

var babelConfig = loaderConfig.use.options;

Expand Down
2 changes: 1 addition & 1 deletion spec/mock/webpack.bad-export.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

var path = require('path');

var defaultConfig = require('hops-config/configs/node');
var defaultConfig = require('hops-build-config/configs/node');

var projectDir = path.resolve(__dirname, 'bad-export');

Expand Down
2 changes: 1 addition & 1 deletion spec/mock/webpack.bad-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

var path = require('path');

var defaultConfig = require('hops-config/configs/node');
var defaultConfig = require('hops-build-config/configs/node');

var projectDir = path.resolve(__dirname, 'bad-handler');

Expand Down
2 changes: 1 addition & 1 deletion spec/mock/webpack.good.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

var path = require('path');

var defaultConfig = require('hops-config/configs/node');
var defaultConfig = require('hops-build-config/configs/node');

var projectDir = path.resolve(__dirname, 'good');

Expand Down

0 comments on commit dbeeb5a

Please sign in to comment.