npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

laravel-mix-ejs

v2.0.1

Published

Laravel Mix extension to compile EJS templates

Downloads

565

Readme

Laravel Mix EJS npm version GitHub license

This extention provides a method to compile EJS templates, in which the mix function is available.

Installation

With laravel-mix@>=6

$ npm install --save-dev laravel-mix-ejs

With laravel-mix@<6

$ npm install --save-dev laravel-mix-ejs@1

Usage

const mix = require('laravel-mix')

require('laravel-mix-ejs')

mix.ejs(
  'src/templates',
  'dist',
  {},
  { base: 'src/templates' }
)

API

ejs(from, to, data, options)

from

Type: string | string[]

Paths or glob patterns to files and directories to be copied.

to

Type: string

Destination path for copied files and directories.

data

Type: object

Overwrites the parameters used in the templates.

mix.ejs(
  'src',
  'dist',
  { title: 'Foo' },
  { base: 'src' }
)
<!-- Input: src/index.ejs -->
<% const heading = 'Bar' %>
<!DOCTYPE html>
<html>
  <head>
    <title><%= title %></title>
  </head>
  <body>
    <h1><%= heading %></h1>
  </body>
</html>

<!-- Output: dist/index.html -->
<!DOCTYPE html>
<html>
  <head>
    <title>Foo</title>
  </head>
  <body>
    <h1>Bar</h1>
  </body>
</html>

Contains the following parameters by default since v2.

[>= v2] mix(filePath)

The mix function. It returns a hashed file path in mix-manifest.json.

Note: Currently, hashes are output only when Laravel Mix versioning is enabled and in production mode. If needed in development mode as well, please use this way.

mix
  .setPublicPath('dist')
  .version()
  .js('src/js/app.js', 'dist/js')
  .sass('src/sass/app.scss', 'dist/css')
  .ejs(
    'src/templates',
    'dist',
    {}, // The `mix` function is provided by default since v2
    { base: 'src/templates' }
  )
<!-- Input: src/templates/index.ejs -->
<!DOCTYPE html>
<html>
  <head>
    <link rel="stylesheet" href="<%= mix('/css/app.css') %>" />
  </head>
  <body>
    <script src="<%= mix('/js/app.js') %>"></script>
  </body>
</html>

<!-- Output: dist/index.html -->
<!DOCTYPE html>
<html>
  <head>
    <link rel="stylesheet" href="/css/app.css?id=5idpn5fikyiybmyajdwnzh4wjx3ufe98" />
  </head>
  <body>
    <script src="/js/app.js?id=9au3gcbe9z8fagg7x6i4ifsmbuur49ig"></script>
  </body>
</html>
[>= v2] webpackCompilation
[>= v2] webpackConfig

options

Type: object

In addition to the EJS options, the following properties can also be set.

base

Type: string
Default: ''

When a path to a directory is set, the directory will be copied with the hierarchical structure kept.

// src/foo/bar.ejs -> dist/bar.html
mix.ejs(
  'src',
  'dist'
)

// src/foo/bar.ejs -> dist/foo/bar.html
mix.ejs(
  'src',
  'dist',
  {},
  { base: 'src' }
)
ext

Type: string
Default: '.html'

Changes the output file extension.

// src/index.ejs -> dist/index.html
mix.ejs(
  'src',
  'dist',
  {},
  { base: 'src' }
)

// src/index.ejs -> dist/index.php
mix.ejs(
  'src',
  'dist',
  {},
  {
    base: 'src',
    ext: '.php'
  }
)
partials

Type: string | string[]
Default: []

Paths set to this option will be watched but not output. Use for partial templates that are used with include().

// src/partials/header.ejs -> dist/partials/header.html
mix.ejs(
  'src',
  'dist',
  {},
  { base: 'src' }
)

// src/partials/header.ejs -> No output
mix.ejs(
  'src',
  'dist',
  {},
  {
    base: 'src',
    partials: 'src/partials'
  }
)