Skip to content

Commit

Permalink
Framework: Use Webpack to inject PROJECT_NAME constant to avoid bundl…
Browse files Browse the repository at this point in the history
…ing all project files into one build file
  • Loading branch information
gziolo committed Apr 12, 2017
1 parent 551dd06 commit c6ab4e8
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 15 deletions.
5 changes: 3 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ module.exports = {
node: true
},
globals: {
asyncRequire: true
asyncRequire: true,
PROJECT_NAME: true
},
rules: {
camelcase: 0, // REST API objects include underscores
Expand All @@ -17,4 +18,4 @@ module.exports = {
'no-restricted-modules': [ 2, 'lib/sites-list', 'lib/mixins/data-observe' ],
'no-unused-expressions': 0, // Allows Chai `expect` expressions
}
};
};
3 changes: 1 addition & 2 deletions client/boot/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import page from 'page';
/**
* Internal dependencies
*/
import config from 'config';
import {
configureReduxStore,
locales,
Expand All @@ -30,7 +29,7 @@ const debug = debugFactory( 'calypso' );
const boot = currentUser => {
debug( "Starting Calypso. Let's do this." );

const project = require( `./project/${ config( 'project' ) }` );
const project = require( `./project/${ PROJECT_NAME }` );

locales( currentUser );
invoke( project, 'locales', currentUser );
Expand Down
8 changes: 3 additions & 5 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/***** WARNING: ES5 code only here. Not transpiled! *****/
/* eslint-disable no-var */
/***** WARNING: No ES6 modules here. Not transpiled! *****/

/**
* External dependencies
Expand Down Expand Up @@ -94,7 +93,8 @@ const webpackConfig = {
new webpack.DefinePlugin( {
'process.env': {
NODE_ENV: JSON.stringify( bundleEnv )
}
},
'PROJECT_NAME': JSON.stringify( config( 'project' ) )
} ),
new WebpackStableBuildPlugin( {
seed: 0
Expand Down Expand Up @@ -216,5 +216,3 @@ if ( config.isEnabled( 'webpack/persistent-caching' ) ) {
webpackConfig.module.loaders = [ jsLoader ].concat( webpackConfig.module.loaders );

module.exports = webpackConfig;

/* eslint-enable no-var */
15 changes: 9 additions & 6 deletions webpack.config.node.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
/***** WARNING: ES5 code only here. Not transpiled! *****/
/***** WARNING: No ES6 modules here. Not transpiled! *****/

/**
* External dependencies
*/
var webpack = require( 'webpack' ),
const webpack = require( 'webpack' ),
path = require( 'path' ),
HardSourceWebpackPlugin = require( 'hard-source-webpack-plugin' ),
fs = require( 'fs' );

/**
* Internal dependencies
*/
var config = require( 'config' );
const config = require( 'config' );

/**
* This lists modules that must use commonJS `require()`s
Expand All @@ -20,7 +20,7 @@ var config = require( 'config' );
* @returns { object } list of externals
*/
function getExternals() {
var externals = {};
const externals = {};

// Don't bundle any node_modules, both to avoid a massive bundle, and problems
// with modules that are incompatible with webpack bundling.
Expand Down Expand Up @@ -53,7 +53,7 @@ function getExternals() {
return externals;
}

var webpackConfig = {
const webpackConfig = {
devtool: 'source-map',
entry: 'index.js',
target: 'node',
Expand Down Expand Up @@ -105,6 +105,9 @@ var webpackConfig = {
plugins: [
// Require source-map-support at the top, so we get source maps for the bundle
new webpack.BannerPlugin( 'require( "source-map-support" ).install();', { raw: true, entryOnly: false } ),
new webpack.DefinePlugin( {
'PROJECT_NAME': JSON.stringify( config( 'project' ) )
} ),
new webpack.NormalModuleReplacementPlugin( /^lib\/analytics$/, 'lodash/noop' ), // Depends on BOM
new webpack.NormalModuleReplacementPlugin( /^lib\/sites-list$/, 'lodash/noop' ), // Depends on BOM
new webpack.NormalModuleReplacementPlugin( /^lib\/olark$/, 'lodash/noop' ), // Depends on DOM
Expand All @@ -119,7 +122,7 @@ var webpackConfig = {
};

if ( config.isEnabled( 'webpack/persistent-caching' ) ) {
webpackConfig.recordsPath = path.join( __dirname, '.webpack-cache', 'server-records.json' ),
webpackConfig.recordsPath = path.join( __dirname, '.webpack-cache', 'server-records.json' );
webpackConfig.plugins.unshift( new HardSourceWebpackPlugin( { cacheDirectory: path.join( __dirname, '.webpack-cache', 'server' ) } ) );
}

Expand Down

0 comments on commit c6ab4e8

Please sign in to comment.