|
|
|
|
|
|
|
|
|
|
|
|
|
|
const spawnSync = require( 'child_process' ).spawnSync; |
|
|
const path = require( 'path' ); |
|
|
const getBaseWebpackConfig = require( '@automattic/calypso-build/webpack.config.js' ); |
|
|
const ExtensiveLodashReplacementPlugin = require( '@automattic/webpack-extensive-lodash-replacement-plugin' ); |
|
|
const HtmlWebpackPlugin = require( 'html-webpack-plugin' ); |
|
|
const { BundleAnalyzerPlugin } = require( 'webpack-bundle-analyzer' ); |
|
|
const GenerateChunksMapPlugin = require( '../../build-tools/webpack/generate-chunks-map-plugin' ); |
|
|
|
|
|
const shouldEmitStats = process.env.EMIT_STATS && process.env.EMIT_STATS !== 'false'; |
|
|
const isDevelopment = process.env.NODE_ENV !== 'production'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function getWebpackConfig( |
|
|
env = {}, |
|
|
{ |
|
|
entry = path.join( __dirname, 'src', 'standalone' ), |
|
|
outputPath = path.join( __dirname, 'dist' ), |
|
|
outputFilename = 'build.min.js', |
|
|
} |
|
|
) { |
|
|
const webpackConfig = getBaseWebpackConfig( env, { |
|
|
entry, |
|
|
'output-filename': outputFilename, |
|
|
'output-path': outputPath, |
|
|
} ); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const gitDescribe = ( |
|
|
process.env.commit_sha ?? |
|
|
spawnSync( 'git', [ 'rev-parse', 'HEAD' ], { |
|
|
encoding: 'utf8', |
|
|
} ).stdout.replace( '\n', '' ) |
|
|
).slice( 0, 11 ); |
|
|
|
|
|
const pageMeta = { |
|
|
'git-describe': gitDescribe, |
|
|
}; |
|
|
|
|
|
return { |
|
|
...webpackConfig, |
|
|
optimization: { |
|
|
concatenateModules: ! shouldEmitStats, |
|
|
}, |
|
|
plugins: [ |
|
|
...webpackConfig.plugins, |
|
|
new HtmlWebpackPlugin( { |
|
|
filename: path.join( outputPath, 'index.html' ), |
|
|
template: path.join( __dirname, 'src', 'index.ejs' ), |
|
|
publicPath: 'https://widgets.wp.com/notifications/', |
|
|
hash: true, |
|
|
inject: false, |
|
|
scriptLoading: 'blocking', |
|
|
meta: pageMeta, |
|
|
includeStyle: ( href ) => ! href.includes( '.rtl.css' ), |
|
|
} ), |
|
|
new HtmlWebpackPlugin( { |
|
|
filename: path.join( outputPath, 'rtl.html' ), |
|
|
template: path.join( __dirname, 'src', 'index.ejs' ), |
|
|
publicPath: 'https://widgets.wp.com/notifications/', |
|
|
hash: true, |
|
|
inject: false, |
|
|
scriptLoading: 'blocking', |
|
|
meta: pageMeta, |
|
|
includeStyle: ( href ) => href.includes( '.rtl.css' ), |
|
|
} ), |
|
|
new GenerateChunksMapPlugin( { |
|
|
output: path.resolve( __dirname, 'dist/chunks-map.json' ), |
|
|
} ), |
|
|
shouldEmitStats && |
|
|
new BundleAnalyzerPlugin( { |
|
|
analyzerMode: 'disabled', |
|
|
generateStatsFile: true, |
|
|
statsFilename: path.join( __dirname, 'stats.json' ), |
|
|
statsOptions: { |
|
|
source: false, |
|
|
reasons: true, |
|
|
optimizationBailout: false, |
|
|
chunkOrigins: false, |
|
|
chunkGroups: true, |
|
|
}, |
|
|
} ), |
|
|
new ExtensiveLodashReplacementPlugin(), |
|
|
].filter( Boolean ), |
|
|
devtool: isDevelopment ? 'inline-cheap-source-map' : 'source-map', |
|
|
}; |
|
|
} |
|
|
|
|
|
module.exports = getWebpackConfig; |
|
|
|