All Projects → Vishal0203 → file-include-webpack-plugin

Vishal0203 / file-include-webpack-plugin

Licence: other
A webpack plugin to include files using @@ include syntax in html files, like gulp-file-include

Programming Languages

javascript
184084 projects - #8 most used programming language
HTML
75241 projects

Projects that are alternatives of or similar to file-include-webpack-plugin

gulp-inject-partials
A recursive injection of partials based on their path name. Implementation of specific case of gulp-inject.
Stars: ✭ 26 (+62.5%)
Mutual labels:  gulp, partials
email-framework
A simple, gulp powered framework to develop and test responsive emails.
Stars: ✭ 19 (+18.75%)
Mutual labels:  gulp, partials
Prometheus
🌈 A Clean And Modern Ghost Theme with Progressive Web Apps (PWA)
Stars: ✭ 94 (+487.5%)
Mutual labels:  gulp
gulp-tinypng-compress
TinyPNG API wrapper for compressing PNG & JPG images
Stars: ✭ 49 (+206.25%)
Mutual labels:  gulp
generator-vars-jekyll
Generator for raw web app with CircleCI, Jekyll, Webpack, Express + more.
Stars: ✭ 18 (+12.5%)
Mutual labels:  gulp
gulp-boilerplate
Gulp boilerplate
Stars: ✭ 24 (+50%)
Mutual labels:  gulp
gulp-starter-kit
My Gulp Starter Kit
Stars: ✭ 91 (+468.75%)
Mutual labels:  gulp
animecenter
The source code for animecenter
Stars: ✭ 16 (+0%)
Mutual labels:  gulp
gulp-iife
A Gulp plugin for wrapping JavaScript code in IIFEs.
Stars: ✭ 39 (+143.75%)
Mutual labels:  gulp
gulp-asciidoctor
gulp-asciidoctor
Stars: ✭ 14 (-12.5%)
Mutual labels:  gulp
gulp-optimize-js
No description or website provided.
Stars: ✭ 23 (+43.75%)
Mutual labels:  gulp
Asteroids
Yep, a gulp-ready-nunjucks-lover-sass-powered-and-humanstxt-included html starter kit!
Stars: ✭ 15 (-6.25%)
Mutual labels:  gulp
aesto
Free Ghost theme with membership support. Minimal content focused design with multi author supported.
Stars: ✭ 31 (+93.75%)
Mutual labels:  gulp
wx-mini
运用webpack编译构建小程序的脚手架(稳定版)
Stars: ✭ 21 (+31.25%)
Mutual labels:  gulp
gulp-recess
[DEPRECATED] Lint CSS and LESS with RECESS
Stars: ✭ 42 (+162.5%)
Mutual labels:  gulp
gulp-webpack-demo
No description or website provided.
Stars: ✭ 12 (-25%)
Mutual labels:  gulp
gulp-cordova
[UNMAINTAINED] Very simple plugin to run cordova commands with a simple interface from gulp
Stars: ✭ 23 (+43.75%)
Mutual labels:  gulp
frontendkickstarter
Gulp 4.0 configuration for static sites development
Stars: ✭ 31 (+93.75%)
Mutual labels:  gulp
generator-speedseed
Oriented to components, allow create/choice template, multiple configuration with easy maintenance
Stars: ✭ 13 (-18.75%)
Mutual labels:  gulp
Carbon.Gulp
Carbon/Gulp is a delicious blend of tasks and build tools poured into Gulp to form a full-featured modern asset pipeline for Flow Framework and Neos CMS.
Stars: ✭ 15 (-6.25%)
Mutual labels:  gulp

File Include Webpack Plugin

A webpack plugin to include files using @@include syntax in html files, like gulp-file-include.

Installation

npm install --save-dev file-include-webpack-plugin

Note: This plugin requires Webpack 4.0.0 and above.

Usage

Webpack Config

Update plugins array in webpack.config.js

// import the plugin
const FileIncludeWebpackPlugin = require('file-include-webpack-plugin')

module.exports = {
  plugins: [
    new FileIncludeWebpackPlugin(
      {
        source: './src/templates', // relative path to your templates
        replace: [{
          regex: /\[\[FILE_VERSION]]/, // additional things to replace
          to: 'v=1.0.0',
        }],
      },
    )
  ]
}

How to pass html beautifier options

This plugin uses js-beautify for html beautification.

Use the config htmlBeautifyOptions to pass custom beautifier options. Refer to the package js-beautify to know more about the possible options.

Example config -

module.exports = {
  plugins: [
    new FileIncludeWebpackPlugin(
      {
        source: './src/templates',
        htmlBeautifyOptions: {
          'indent_size': 2
        }
      },
    )
  ]
}

How to change the output destination?

destination is an optional configuration, which is relative to output.path in webpack configuration.

module.exports = {
  plugins: [
    new FileIncludeWebpackPlugin(
      {
        source: './src/templates',
        destination: '../html',
      },
    )
  ]
}

Template Syntax

Add templates using @@ as shown below

@@inlude('../partials/header.html')   //relative path to partials from parent html

Include partials inside partials

With release v1.3.5, you can now include partials inside other partials. Use relative path w.r.t. including parent.

Passing arguments to partials

file-include-webpack-plugin allows passing substitutable arguments as a key-value JSON to the included files.

@@inlude('../partials/header.html', {
  "arg1": "value1",
  "arg2": "value2",
  "arg3": {
    "arg3a": "value3a",
    "arg3b": "value3b",
  },
  ...
})

Access the arguments in partials as @@arg1, @@arg2, @@arg3.arg3a, and so on. Refer example for complete reference.

Note:

  • Currently, only supports value substitution. Passing an array or an object as value, may not give intended output.
  • Please raise an issue for any new requirements.

Working with example

Switch to example directory and run npm install. Running npm run build post installation will now generate a directory dist with all the partials included in templates.

Run npm run watch to run webpack in watch mode, to continue developing and re-compiling webpack on every change.

Or, run npm run dev to launch webpack dev server.

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].