From 5447e334dcb21a7fb736bccf68a33bd6e0c78c41 Mon Sep 17 00:00:00 2001 From: Sean Yesmunt Date: Wed, 19 Aug 2020 17:09:30 -0400 Subject: [PATCH] use dynamic js bundle urls --- static/index-web.html | 1 - web/bundle-id.js | 8 ++++++++ web/package.json | 6 ++++-- web/src/html.js | 7 ++++++- web/webpack.config.js | 9 ++++++++- web/yarn.lock | 27 +++++++++++++++++++++++++-- 6 files changed, 51 insertions(+), 7 deletions(-) create mode 100644 web/bundle-id.js diff --git a/static/index-web.html b/static/index-web.html index f97bade35..b9ffe6fd2 100644 --- a/static/index-web.html +++ b/static/index-web.html @@ -3,7 +3,6 @@ - diff --git a/web/bundle-id.js b/web/bundle-id.js new file mode 100644 index 000000000..80530a28d --- /dev/null +++ b/web/bundle-id.js @@ -0,0 +1,8 @@ +const uuid = require('uuid/v4'); +const jsBundleId = uuid(); + +function getJsBundleId() { + return jsBundleId; +} + +module.exports = { getJsBundleId }; diff --git a/web/package.json b/web/package.json index 69547e350..1115e19f0 100644 --- a/web/package.json +++ b/web/package.json @@ -34,7 +34,8 @@ "lbry-redux": "lbryio/lbry-redux#c107d9cc4c4b2cc31f182f196ab6a033aefe976e", "lbryinc": "lbryio/lbryinc#6a52f8026cdc7cd56d200fb5c46f852e0139bbeb", "mysql": "^2.17.1", - "node-fetch": "^2.6.0" + "node-fetch": "^2.6.0", + "uuid": "^8.3.0" }, "devDependencies": { "@babel/core": "^7.0.0", @@ -54,6 +55,7 @@ "webpack": "^4.41.2", "webpack-bundle-analyzer": "^3.6.0", "webpack-dev-server": "^3.9.0", - "webpack-merge": "^4.2.2" + "webpack-merge": "^4.2.2", + "write-file-webpack-plugin": "^4.5.1" } } diff --git a/web/src/html.js b/web/src/html.js index 3532d6e83..ee38225cf 100644 --- a/web/src/html.js +++ b/web/src/html.js @@ -14,11 +14,16 @@ const { getClaim } = require('./chainquery'); const { parseURI } = require('lbry-redux'); const fs = require('fs'); const path = require('path'); +const { getJsBundleId } = require('../bundle-id.js'); +const jsBundleId = getJsBundleId(); function insertToHead(fullHtml, htmlToInsert) { return fullHtml.replace( /.*/s, - htmlToInsert || buildOgMetadata() + ` + ${htmlToInsert || buildOgMetadata()} + + ` ); } diff --git a/web/webpack.config.js b/web/webpack.config.js index c89753fb2..33ac21b47 100644 --- a/web/webpack.config.js +++ b/web/webpack.config.js @@ -4,8 +4,10 @@ const fs = require('fs'); const merge = require('webpack-merge'); const baseConfig = require('../webpack.base.config.js'); const CopyWebpackPlugin = require('copy-webpack-plugin'); +const WriteFilePlugin = require('write-file-webpack-plugin'); const { DefinePlugin, ProvidePlugin } = require('webpack'); const SentryWebpackPlugin = require('@sentry/webpack-plugin'); +const { getJsBundleId } = require('./bundle-id.js'); const { insertToHead, buildBasicOgMetadata } = require('./src/html'); const { insertVariableXml, getOpenSearchXml } = require('./src/xml'); @@ -16,6 +18,7 @@ const DIST_ROOT = path.resolve(__dirname, 'dist/'); const WEB_PLATFORM_ROOT = __dirname; const isProduction = process.env.NODE_ENV === 'production'; const hasSentryToken = process.env.SENTRY_AUTH_TOKEN !== undefined; +const jsBundleId = getJsBundleId(); const copyWebpackCommands = [ { @@ -24,6 +27,7 @@ const copyWebpackCommands = [ transform(content, path) { return insertToHead(content.toString(), buildBasicOgMetadata()); }, + force: true, }, { from: `${STATIC_ROOT}/opensearch.xml`, @@ -31,10 +35,12 @@ const copyWebpackCommands = [ transform(content, path) { return insertVariableXml(content.toString(), getOpenSearchXml()); }, + force: true, }, { from: `${STATIC_ROOT}/img/favicon.png`, to: `${DIST_ROOT}/public/favicon.png`, + force: true, }, { from: `${STATIC_ROOT}/img/v2-og.png`, @@ -56,6 +62,7 @@ if (fs.existsSync(CUSTOM_OG_PATH)) { } let plugins = [ + new WriteFilePlugin(), new CopyWebpackPlugin(copyWebpackCommands), new DefinePlugin({ IS_WEB: JSON.stringify(true), @@ -80,7 +87,7 @@ if (isProduction && hasSentryToken) { const webConfig = { target: 'web', entry: { - ui: '../ui/index.jsx', + [`ui-${jsBundleId}`]: '../ui/index.jsx', }, output: { filename: '[name].js', diff --git a/web/yarn.lock b/web/yarn.lock index b43340d3b..2a8ad90ac 100644 --- a/web/yarn.lock +++ b/web/yarn.lock @@ -1514,7 +1514,7 @@ capture-stack-trace@^1.0.0: resolved "https://registry.yarnpkg.com/capture-stack-trace/-/capture-stack-trace-1.0.1.tgz#a6c0bbe1f38f3aa0b92238ecb6ff42c344d4135d" integrity sha512-mYQLZnx5Qt1JgB1WEiMCf2647plpGeQ2NMR/5L0HNZzGQo4fuSPnK+wjfPnKZV0aiJDgzmWqqkV/g7JD+DW0qw== -chalk@^2.0.0, chalk@^2.0.1, chalk@^2.4.1, chalk@^2.4.2: +chalk@^2.0.0, chalk@^2.0.1, chalk@^2.4.0, chalk@^2.4.1, chalk@^2.4.2: version "2.4.2" resolved "https://registry.yarnpkg.com/chalk/-/chalk-2.4.2.tgz#cd42541677a54333cf541a49108c1432b44c9424" integrity sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ== @@ -3647,6 +3647,11 @@ mkdirp@^0.5.0, mkdirp@^0.5.1: dependencies: minimist "0.0.8" +moment@^2.22.1: + version "2.27.0" + resolved "https://registry.yarnpkg.com/moment/-/moment-2.27.0.tgz#8bff4e3e26a236220dfe3e36de756b6ebaa0105d" + integrity sha512-al0MUK7cpIcglMv3YF13qSgdAIqxHTO7brRtaz3DlSULbqfazqkc5kEjNrLDOM7fsjshoFIihnU8snrP7zUvhQ== + move-concurrently@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/move-concurrently/-/move-concurrently-1.0.1.tgz#be2c005fda32e0b29af1f05d7c4b33214c701f92" @@ -5413,6 +5418,11 @@ uuid@^3.0.1, uuid@^3.3.2: resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.3.3.tgz#4568f0216e78760ee1dbf3a4d2cf53e224112866" integrity sha512-pW0No1RGHgzlpHJO1nsVrHKpOEIxkGg1xB+v0ZmdNH5OAeAwzAVrCnI2/6Mtx+Uys6iaylxa+D3g4j63IKKjSQ== +uuid@^8.3.0: + version "8.3.0" + resolved "https://registry.yarnpkg.com/uuid/-/uuid-8.3.0.tgz#ab738085ca22dc9a8c92725e459b1d507df5d6ea" + integrity sha512-fX6Z5o4m6XsXBdli9g7DtWgAx+osMsRRZFKma1mIUsLCz6vRvv+pz5VNbyu9UEDzpMWulZfvpgb/cmDXVulYFQ== + vary@^1.1.2, vary@~1.1.2: version "1.1.2" resolved "https://registry.yarnpkg.com/vary/-/vary-1.1.2.tgz#2299f02c6ded30d4a5961b0b9f74524a18f634fc" @@ -5627,7 +5637,7 @@ wrappy@1: resolved "https://registry.yarnpkg.com/wrappy/-/wrappy-1.0.2.tgz#b5243d8f3ec1aa35f1364605bc0d1036e30ab69f" integrity sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8= -write-file-atomic@^2.0.0: +write-file-atomic@^2.0.0, write-file-atomic@^2.3.0: version "2.4.3" resolved "https://registry.yarnpkg.com/write-file-atomic/-/write-file-atomic-2.4.3.tgz#1fd2e9ae1df3e75b8d8c367443c692d4ca81f481" integrity sha512-GaETH5wwsX+GcnzhPgKcKjJ6M2Cq3/iZp1WyY/X1CSqrW+jVNM9Y7D8EC2sM4ZG/V8wZlSniJnCKWPmBYAucRQ== @@ -5636,6 +5646,19 @@ write-file-atomic@^2.0.0: imurmurhash "^0.1.4" signal-exit "^3.0.2" +write-file-webpack-plugin@^4.5.1: + version "4.5.1" + resolved "https://registry.yarnpkg.com/write-file-webpack-plugin/-/write-file-webpack-plugin-4.5.1.tgz#aeeb68889194da5ec8a864667d46da9e00ee92d5" + integrity sha512-AZ7qJUvhTCBiOtG21aFJUcNuLVo2FFM6JMGKvaUGAH+QDqQAp2iG0nq3GcuXmJOFQR2JjpjhyYkyPrbFKhdjNQ== + dependencies: + chalk "^2.4.0" + debug "^3.1.0" + filesize "^3.6.1" + lodash "^4.17.13" + mkdirp "^0.5.1" + moment "^2.22.1" + write-file-atomic "^2.3.0" + ws@^6.0.0, ws@^6.2.1: version "6.2.1" resolved "https://registry.yarnpkg.com/ws/-/ws-6.2.1.tgz#442fdf0a47ed64f59b6a5d8ff130f4748ed524fb"