Snippets

Oleg Chulakov Studio Next.js CDN

Updated by Владимир Самсонов

File style.styl Modified

  • Ignore whitespace
  • Hide word diff
-background-image: url(ASSET_PREFIX + ‘/static/img.jpg’);
+background-image: url(ASSET_PREFIX + '/static/img.jpg');
Updated by Владимир Самсонов

File component.jsx Added

  • Ignore whitespace
  • Hide word diff
+<img src={`${process.env.ASSET_PREFIX}/static/images/logo.svg`} alt="Brand Logo" />

File style.styl Added

  • Ignore whitespace
  • Hide word diff
+background-image: url(ASSET_PREFIX + ‘/static/img.jpg’);
Created by Артем Смирнов

File next.config.js Added

  • Ignore whitespace
  • Hide word diff
+const withStylus = require('@zeit/next-stylus');
+const withCSS = require('@zeit/next-css');
+require('dotenv').config();
+const dev = process.env.NODE_ENV !== 'production';
+
+const ASSET_PREFIX = dev ? '' : process.env.ASSET_PREFIX; // префикс только в production-режиме
+
+const config = {
+  assetPrefix: ASSET_PREFIX, // префикс для ассетов(стили, скрипты)
+  stylusLoaderOptions: {
+    define: {
+      ASSET_PREFIX, // пробрасываем переменную ASSET_PREFIX в Stylus
+    },
+  },
+  env: {
+    ASSET_PREFIX, // пробрасываем переменную окружения в приложение
+  },
+};
+
+module.exports = withCSS(withStylus(config));
HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.