|
|
const webpack = require( 'webpack' ); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function cssNameFromFilename( name ) { |
|
|
if ( name ) { |
|
|
const [ cssChunkFilename, chunkQueryString ] = name.split( '?', 2 ); |
|
|
return cssChunkFilename.replace( |
|
|
/\.js$/i, |
|
|
'.css' + ( chunkQueryString ? `?${ chunkQueryString }` : '' ) |
|
|
); |
|
|
} |
|
|
} |
|
|
|
|
|
function IncrementalProgressPlugin() { |
|
|
function createProgressHandler() { |
|
|
const startTime = Date.now(); |
|
|
let lastShownBuildingMessageTime = null; |
|
|
let lastUnshownBuildingMessage = null; |
|
|
|
|
|
return ( percentage, msg, ...details ) => { |
|
|
const nowTime = Date.now(); |
|
|
const timeString = ( ( nowTime - startTime ) / 1000 ).toFixed( 1 ) + 's'; |
|
|
const percentageString = `${ Math.floor( percentage * 100 ) }%`; |
|
|
const detailsString = details |
|
|
.map( ( detail ) => { |
|
|
if ( ! detail ) { |
|
|
return ''; |
|
|
} |
|
|
if ( detail.length > 40 ) { |
|
|
return `…${ detail.substr( detail.length - 39 ) }`; |
|
|
} |
|
|
return detail; |
|
|
} ) |
|
|
.join( ' ' ); |
|
|
const message = `${ timeString } ${ percentageString } ${ msg } ${ detailsString }`; |
|
|
|
|
|
|
|
|
|
|
|
if ( msg === 'building' ) { |
|
|
if ( lastShownBuildingMessageTime && nowTime - lastShownBuildingMessageTime < 1000 ) { |
|
|
|
|
|
lastUnshownBuildingMessage = message; |
|
|
return; |
|
|
} |
|
|
|
|
|
|
|
|
lastShownBuildingMessageTime = nowTime; |
|
|
lastUnshownBuildingMessage = null; |
|
|
} else if ( lastUnshownBuildingMessage ) { |
|
|
|
|
|
|
|
|
console.log( lastUnshownBuildingMessage ); |
|
|
lastUnshownBuildingMessage = null; |
|
|
} |
|
|
|
|
|
console.log( message ); |
|
|
}; |
|
|
} |
|
|
return new webpack.ProgressPlugin( createProgressHandler() ); |
|
|
} |
|
|
|
|
|
const nodeModulesToTranspile = [ |
|
|
|
|
|
|
|
|
|
|
|
'@automattic/calypso-polyfills/', |
|
|
'@automattic/lasagna/', |
|
|
'@automattic/react-virtualized/', |
|
|
'@github/webauthn-json/', |
|
|
'acorn-jsx/', |
|
|
'chalk/', |
|
|
'd3-array/', |
|
|
'd3-scale/', |
|
|
'debug/', |
|
|
'dom7/', |
|
|
'escape-string-regexp/', |
|
|
'filesize/', |
|
|
'gridicons/', |
|
|
'prismjs/', |
|
|
'punycode/', |
|
|
'query-string/', |
|
|
'react-spring/', |
|
|
'regenerate-unicode-properties/', |
|
|
'regexpu-core/', |
|
|
'split-on-first/', |
|
|
'strict-uri-encode/', |
|
|
'striptags/', |
|
|
'swiper/', |
|
|
'unicode-match-property-ecmascript/', |
|
|
'unicode-match-property-value-ecmascript/', |
|
|
'calypso/', |
|
|
]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function shouldTranspileDependency( filepath ) { |
|
|
|
|
|
|
|
|
const marker = '/node_modules/'; |
|
|
const lastIndex = filepath.lastIndexOf( marker ); |
|
|
if ( lastIndex === -1 ) { |
|
|
|
|
|
return false; |
|
|
} |
|
|
|
|
|
const checkFrom = lastIndex + marker.length; |
|
|
|
|
|
return nodeModulesToTranspile.some( ( modulePart ) => |
|
|
filepath.startsWith( modulePart, checkFrom ) |
|
|
); |
|
|
} |
|
|
|
|
|
module.exports = { cssNameFromFilename, IncrementalProgressPlugin, shouldTranspileDependency }; |
|
|
|