Every day is a learning day at Strapi
I have found the solution to load .env variables for this preview link…
Please refer to the following discussions:
Essentially, we cannot load .env variables into the “frontend” of Strapi (the frontend includes plugins and extensions are plugin extensions).
Therefore we have to customise webpack.
Create a file ./admin/admin.config.js with the folllowing:
module.exports = {
webpack: (config, webpack) => {
const definePlugin = new webpack.DefinePlugin({
CLIENT_URL: JSON.stringify(process.env.CLIENT_URL),
CLIENT_PREVIEW_SECRET: JSON.stringify(
process.env.CLIENT_PREVIEW_SECRET
),
});
config.plugins.push(definePlugin);
return config;
},
};
Then do following:
- delete the
./build
and./cache
folders. yarn build --clean
Now you will be able to access CLIENT_URL
and CLIENT_PREVIEW_SECRET
in ./extensions/admin/src/InjectedComponents/ExternalLink/index.js