Skip to content

Commit

Permalink
Merge pull request #2736 from cfpb/es6_babel_setup
Browse files Browse the repository at this point in the history
Adding Babel to frontend workflow; Upgrading Webpack to version 2.
  • Loading branch information
sebworks authored Mar 2, 2017
2 parents 06c6332 + dd4c4d8 commit 13ac0c7
Show file tree
Hide file tree
Showing 5 changed files with 3,162 additions and 355 deletions.
9 changes: 9 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"presets": ["es2015", "stage-2"],
"env": {
// only happens if NODE_ENV is undefined or set to 'development'
"development": {
// ignored when NODE_ENV is production!
}
}
}
23 changes: 16 additions & 7 deletions config/webpack-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,26 @@ var modernConf = {
// so it needs to be defined here as an external script to ignore for
// unmet dependency references.
externals: { jquery: 'jQuery' },
context: path.join( __dirname, '/../', paths.unprocessed, JS_ROUTES_PATH ),
entry: scriptsManifest.getDirectoryMap( paths.unprocessed +
JS_ROUTES_PATH ),
cache: true,
context: path.join( __dirname, '/../', paths.unprocessed, JS_ROUTES_PATH ),
entry: scriptsManifest.getDirectoryMap( paths.unprocessed + JS_ROUTES_PATH ),
module: {
rules: [ {
test: /\.js$/,
use: [ {
loader: 'babel-loader?cacheDirectory=true'
} ],
exclude: /node_modules/
} ]
},
output: {
path: path.join( __dirname, 'js' ),
path: path.join( __dirname, 'js' ),
filename: '[name]'
},
plugins: [
new webpack.optimize.CommonsChunkPlugin( COMMON_BUNDLE_NAME ),
new webpack.optimize.CommonsChunkPlugin( COMMON_BUNDLE_NAME,
[ COMMON_BUNDLE_NAME ] ),
new webpack.optimize.CommonsChunkPlugin( {
name: COMMON_BUNDLE_NAME
} ),
// Change `warnings` flag to true to view linter-style warnings at runtime.
new webpack.optimize.UglifyJsPlugin( {
compress: { warnings: false }
Expand Down
7 changes: 4 additions & 3 deletions gulp/tasks/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ var gulpReplace = require( 'gulp-replace' );
var gulpUglify = require( 'gulp-uglify' );
var handleErrors = require( '../utils/handle-errors' );
var paths = require( '../../config/environment' ).paths;
var webpack = require( 'webpack' );
var webpackConfig = require( '../../config/webpack-config.js' );
var webpackStream = require( 'webpack-stream' );
var configLegacy = require( '../config.js' ).legacy;
Expand All @@ -30,7 +31,7 @@ var configLegacy = require( '../config.js' ).legacy;
*/
function _processScript( config, src, dest ) {
return gulp.src( paths.unprocessed + src )
.pipe( webpackStream( config ) )
.pipe( webpackStream( config, webpack ) )
.on( 'error', handleErrors )
.pipe( gulp.dest( paths.processed + dest ) )
.pipe( browserSync.reload( {
Expand Down Expand Up @@ -108,7 +109,7 @@ function scriptsOnDemand() {
*/
function scriptsNonResponsive() {
return gulp.src( paths.unprocessed + '/js/routes/on-demand/header.js' )
.pipe( webpackStream( webpackConfig.onDemandHeaderRawConf ) )
.pipe( webpackStream( webpackConfig.onDemandHeaderRawConf, webpack ) )
.on( 'error', handleErrors )
.pipe( gulpRename( 'header.nonresponsive.js' ) )
.pipe( gulpReplace( 'breakpointState.isInDesktop()', 'true' ) )
Expand Down Expand Up @@ -146,7 +147,7 @@ function scriptsEs5Shim() {
output: {
filename: 'es5-shim.js'
}
} ) )
}, webpack ) )
.pipe( gulpUglify() )
.on( 'error', handleErrors )
.pipe( gulp.dest( paths.processed + '/js/' ) )
Expand Down
Loading

0 comments on commit 13ac0c7

Please sign in to comment.