-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
194 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ dist | |
.changeset | ||
README.md | ||
CHANGELOG.md | ||
riff-raff.yaml | ||
.vscode/settings.json | ||
playwright-report/ | ||
pnpm-lock.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
regions: [eu-west-1] | ||
stacks: [frontend] | ||
allowedStages: | ||
- CODE | ||
- PROD | ||
deployments: | ||
frontend-static/commercial: | ||
type: aws-s3 | ||
parameters: | ||
bucketSsmKey: /account/services/dotcom-static.bucket | ||
cacheControl: public, max-age=315360000, immutable | ||
prefixStack: false | ||
publicReadAcl: false | ||
commercial-bundle-path: | ||
type: cloud-formation | ||
parameters: | ||
templateStagePaths: | ||
CODE: code.json | ||
PROD: prod.json | ||
dependencies: | ||
- frontend-static/commercial |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
import { execSync } from 'child_process'; | ||
import { join } from 'path'; | ||
import TerserPlugin from 'terser-webpack-plugin'; | ||
import webpack from 'webpack'; | ||
import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer'; | ||
import { merge } from 'webpack-merge'; | ||
import config from './webpack.config.mjs'; | ||
|
||
const { DefinePlugin } = webpack; | ||
|
||
class GenerateCloudformation { | ||
apply = (compiler) => { | ||
compiler.hooks.afterEmit.tap('AfterEmitPlugin', (compilation) => { | ||
const entry = compilation.entrypoints.get('commercial-standalone'); | ||
|
||
const hashedFilePath = entry?.getFiles()[0]; | ||
|
||
if (!hashedFilePath) { | ||
throw new Error( | ||
'Could not find hashed file for commercial-standalone', | ||
); | ||
} | ||
|
||
const stages = ['code', 'prod']; | ||
stages.forEach((stage) => { | ||
/** | ||
* This small bit of cloudformation will update the SSM parameter that frontend | ||
* reads to get the bundle path. | ||
*/ | ||
const cloudformation = { | ||
Resources: { | ||
BundlePath: { | ||
Type: 'AWS::SSM::Parameter', | ||
Properties: { | ||
Name: `/frontend/${stage}/commercial.bundlePath`, | ||
Type: 'String', | ||
Value: hashedFilePath, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
// If we're in prod, we also want to update the dev bundle path | ||
if (stage === 'prod') { | ||
cloudformation.Resources.DevBundlePath = { | ||
Type: 'AWS::SSM::Parameter', | ||
Properties: { | ||
Name: '/frontend/dev/commercial.bundlePath', | ||
Type: 'String', | ||
Value: hashedFilePath, | ||
}, | ||
}; | ||
} | ||
|
||
const output = JSON.stringify(cloudformation, null, 2); | ||
const outputPath = join( | ||
import.meta.dirname, | ||
'dist', | ||
'riff-raff', | ||
'cloudformation', | ||
`${stage}.json`, | ||
); | ||
compiler.outputFileSystem.mkdirSync( | ||
join( | ||
import.meta.dirname, | ||
'dist', | ||
'riff-raff', | ||
'cloudformation', | ||
), | ||
{ recursive: true }, | ||
); | ||
compiler.outputFileSystem.writeFileSync(outputPath, output); | ||
}); | ||
}); | ||
}; | ||
} | ||
|
||
const gitCommitSHA = () => { | ||
try { | ||
const commitSHA = execSync('git rev-parse HEAD').toString().trim(); | ||
return { 'process.env.COMMIT_SHA': JSON.stringify(commitSHA) }; | ||
} catch (_) { | ||
return {}; | ||
} | ||
}; | ||
|
||
const prefix = process.env.BUNDLE_PREFIX ?? '[chunkhash]/'; | ||
|
||
// eslint-disable-next-line import/no-default-export -- webpack config | ||
export default merge(config, { | ||
mode: 'production', | ||
output: { | ||
filename: `commercial/${prefix}graun.standalone.commercial.js`, | ||
chunkFilename: `commercial/${prefix}graun.[name].commercial.js`, | ||
path: join(import.meta.dirname, 'dist', 'riff-raff', 'js'), | ||
publicPath: 'auto', | ||
clean: true, | ||
}, | ||
devtool: 'source-map', | ||
plugins: [ | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-call -- circular-dependency-plugin is not typed | ||
new BundleAnalyzerPlugin({ | ||
reportFilename: './commercial-bundle-analyzer-report.html', | ||
analyzerMode: 'static', | ||
openAnalyzer: false, | ||
}), | ||
new DefinePlugin({ | ||
'process.env.NODE_ENV': JSON.stringify('production'), | ||
'process.env.OVERRIDE_BUNDLE_PATH': JSON.stringify(false), | ||
'process.env.RIFFRAFF_DEPLOY': JSON.stringify(true), | ||
...gitCommitSHA(), | ||
}), | ||
new GenerateCloudformation(), | ||
], | ||
optimization: { | ||
minimize: true, | ||
minimizer: [new TerserPlugin()], | ||
}, | ||
}); |