All Projects → jimmy319 → amp-react-renderer-plugin

jimmy319 / amp-react-renderer-plugin

Licence: MIT license
⚡Plugin makes it painless to create React component based AMP page⚡

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to amp-react-renderer-plugin

amp-mui
⚡ AMP MUI CSS Framework
Stars: ✭ 18 (-37.93%)
Mutual labels:  amp, amp-html
amp-converter
A PHP library to convert HTML articles, blog posts or similar content to AMP (Accelerated Mobile Pages).
Stars: ✭ 59 (+103.45%)
Mutual labels:  amp, amp-html
amp-browser
AMP Browser
Stars: ✭ 39 (+34.48%)
Mutual labels:  amp, amp-html
amp-renderer
Server-side rendering for AMP in Python
Stars: ✭ 14 (-51.72%)
Mutual labels:  amp, amp-html
ampjucks
Boilerplate and base project to create static websites with AMP, Nunjucks and Gulp
Stars: ✭ 18 (-37.93%)
Mutual labels:  amp, amp-html
react-amp-components
A (hopefully) simple way to render AMP components via React on the server.
Stars: ✭ 30 (+3.45%)
Mutual labels:  amp, amp-html
wordpress-amp-theme
A free WordPress theme for blogging built entirely on Google AMP
Stars: ✭ 22 (-24.14%)
Mutual labels:  amp, amp-html
amp-surface
⚡ AMP Surface CSS Framework
Stars: ✭ 26 (-10.34%)
Mutual labels:  amp, amp-html
webpack-stats-diff-plugin
Webpack plugin for reporting changes in bundle sizes across builds
Stars: ✭ 63 (+117.24%)
Mutual labels:  webpack-plugin
web-stories-wp
Web Stories for WordPress
Stars: ✭ 695 (+2296.55%)
Mutual labels:  amp
loading-screen
🚥Loading screen for webpack plugin inspired by Nuxt.js's loading screen
Stars: ✭ 56 (+93.1%)
Mutual labels:  webpack-plugin
monaco-editor-esm-webpack-plugin
No description or website provided.
Stars: ✭ 25 (-13.79%)
Mutual labels:  webpack-plugin
webpack2-externals-plugin
Webpack 2+ fork of Webpack-Externals-Plugin
Stars: ✭ 14 (-51.72%)
Mutual labels:  webpack-plugin
AMP-dockerized
CubeCoders AMP in a Docker Image. Easily create game servers for games like Minecraft, GMod, TF2, Factorio, and StarBound!
Stars: ✭ 54 (+86.21%)
Mutual labels:  amp
generate-package-json-webpack-plugin
Generates a package.json file containing the external modules used by your webpack bundle
Stars: ✭ 59 (+103.45%)
Mutual labels:  webpack-plugin
webpack-alioss-upload-plugin
A flexible webpack plugin to upload files to aliyun oss, which supports multiple optional upload methods and parameters.
Stars: ✭ 14 (-51.72%)
Mutual labels:  webpack-plugin
webpack-shower
🚿 Clean up, Arrange, Filter Webpack Stats
Stars: ✭ 12 (-58.62%)
Mutual labels:  webpack-plugin
stylelint-bare-webpack-plugin
Stylelint plugin for webpack
Stars: ✭ 15 (-48.28%)
Mutual labels:  webpack-plugin
image-sprite-webpack-plugin
A webpack plugin that generates spritesheets from your stylesheets.
Stars: ✭ 27 (-6.9%)
Mutual labels:  webpack-plugin
prettier-eslint-webpack-plugin
Webpack plugin for prettier-eslint which ESLint's settings is set to JavaScript Standard Style
Stars: ✭ 24 (-17.24%)
Mutual labels:  webpack-plugin

AMP React Renderer Plugin

Component Build Npm Publish

This ia a webpack plugin that make it painless to create a React component based AMP (Google Accelerated Mobile Pages) application easily. It can handle these jobs for you:

  • Collect custom CSS: Move all application required CSS assets into an AMP boilerplate HTML renderer. Renderer will add these styles inside the amp custom style tag of head tag.

  • Load used extension library automatically: Extract the application used AMP extension component from bundle and generate cooresponding library script tags which will be added to the head tag of AMP HTML renderer.

  • Generate a React based AMP HTML renderer: Plugin will generate a AMP HTML renderer for each application entry. It's a function that can be invoked with page meta and React application component at server runtime. Be able to render with React component means that plugin produced renderer works well with React ecosystem libraries which can be used on the server side like Redux and React Router. You can refer to the examples for more details and give it a try.

Demo

screencast_1080

Installation

$ npm i -D amp-react-renderer-plugin

Usage

webpack.config.js

[Note] This plugin need to use together with plugins which can extract all required css modules in chunk into single or mutiple .css files such as ExtractTextPlugin for webpack 3 or mini-css-extract-plugin for webpack 4.

const AmpReactRendererPlugin = require('amp-react-renderer-plugin')

module.exports = {
  mode: ' development',
  entry: {
    'home': 'index.js'
  },
  output: {
    path: __dirname + '/dist',
    filename: '[name].js'
  },
  module: {
    rules: [
      {
        test: /\.js$/,
        use: 'babel-loader'
      },
      {
        test: /\.css$/,
        use: ExtractTextPlugin.extract({
          use: [
            {
              loader: 'css-loader',
              query: {
                minimize: true
              }
            }
          ]
        })
      }
    ]
  },
  plugins: [
    new AmpReactRendererPlugin()
  ]
}

This will generate a file dist/AmpHtmlRenderer.js which will be used to render AMP page with React application component at server runtime.

AMP page rendering

Here we use express route handler as example:

const ampHtmlRenderer = require('./dist/AmpHtmlRenderer.js')

app.get('/home', function (req ,res) {
  const Application = require('./components/Application')

  res.send(ampHtmlRenderer({
    entryName: 'home',
    AppComponent: <Application />,
    title: 'hello AMP x React',
    canonical: 'https://github.com',
    headComponents: [<meta property="fb:app_id" content="1401488693436528"/>]
  }))
})

Setup for live reload development

// webpack.dev.config
const WriteFilePlugin = require('write-file-webpack-plugin')

plugins: [
  ...,
  new WriteFilePlugin()
]
const path = require('path')
const webpackConfig = require('../webpack.config.dev.js')
const webpackDevMiddleware = require('webpack-dev-middleware')
const webpack = require('webpack')
const compiler = webpack(webpackConfig)
const server = require('./server.js')

// apply webpack dev middleware to enable Amp Html Renderer auto rebuilding
server.use(webpackDevMiddleware(compiler))
  • Step3: use nodemon to monitor source changes in application and restart server automatically
$ nodemon --watch src/ server.js

[Note] Examples demonstrate how to setup it, check it out

AmpHtmlRenderer

generate AMP HTML source with options you passed in

Options

You need to pass a hash of options to AmpHtmlRenderer

name type description
entryName String name of the entry point for the bundle which is used to generate renderer
AppComponent React Element application React element
title String page title
canonical String canonical link
headComponents Array collection of React elements which will be added inside of HTML head tag
runtimeCss String javascript generated inline style source. For example: Styled Components collectStyles()

Why component-based AMP

More Maintainable

2018-05-10 10 09 16

Composable

2018-05-10 10 09 28

Easy to share and reuse

2018-05-10 10 09 46

Examples

Unsupported extension list

  • amp-ad-exit: Currently renderer doesn't support AMP A4A document
  • amp-google-vrview-image: still get validation error
  • amp-dynamic-css-classes
  • amp-viz-vega

Related Repositories

License

MIT Licensed

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].