unlock-protocol / unlock

Ʉnlock is a protocol for memberships built on a blockchain.
https://unlock-protocol.com
MIT License
835 stars 244 forks source link

Ad remover paywall: build script for unlock.min.js #3365

Closed cellog closed 5 years ago

cellog commented 5 years ago

The build script for unlock.min.js needs to do 1 very important thing:

Build the data iframe, by both tree shaking and code splitting so that it is as small as possible, and the cache handler/post office portion is split from the huge blockchain portion. This is accomplished partially by the usage of import().then() inside the data iframe source, and partially by build steps.

It will be built using webpack (not rollup initially).

In addition, the script responds to UNLOCK_ENV. The code could choose to hard-code values for LOCKSMITH_URI and READ_ONLY_PROVIDER but currently is designed to use env variables:

const constants = {
  dev: {
    unlockAddress: '0x885EF47c3439ADE0CB9b33a4D3c534C99964Db93',
    blockTime: 3000,
    requiredConfirmations: 6,
    locksmithHost: process.env.LOCKSMITH_URI,
    readOnlyProvider: process.env.READ_ONLY_PROVIDER,
  },
  staging: {
    unlockAddress: '0xD8C88BE5e8EB88E38E6ff5cE186d764676012B0b',
    blockTime: 8000,
    requiredConfirmations: 12,
    locksmithHost: process.env.LOCKSMITH_URI,
    readOnlyProvider: process.env.READ_ONLY_PROVIDER,
  },
  prod: {
    unlockAddress: '0x3d5409CcE1d45233dE1D4eBDEe74b8E004abDD13',
    blockTime: 8000,
    requiredConfirmations: 12,
    locksmithHost: process.env.LOCKSMITH_URI,
    readOnlyProvider: process.env.READ_ONLY_PROVIDER,
  },
}

This introduces significantly more complexity, so if it is acceptable, hard-coding will be a better solution.

If we decide to go with the current approach, the script will need to have access to the different values needed for staging and production in CircleCI and ensure we deploy the correct script version to production.

An alternative is to build 3 versions of the script, dev.unlock.min.js, staging.unlock.min.js, and unlock.min.js.

Additionally, the script should be versioned, so initially we will output unlock.1.0.min.js

cellog commented 5 years ago

done!