• Stars
    star
    103
  • Rank 333,046 (Top 7 %)
  • Language
    JavaScript
  • Created over 5 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

๐Ÿ‘จโ€๐Ÿ’ป A capable website/webapp boilerplate ready for the web agency battlefield. Creates a static site with Twig templating by default. Supports Craft/Wordpress/Laravel after a few adjustments.

Agency Webpack Mix Config

Icon

Featuring a top-class developer experience and simple filing system for your project assets, this config provides a solid platform for your next website (or web app).

Features

Sensible configuration complexity

Because of the complexity of raw Webpack configs, they can take an extended time to understand. Laravel Mix provides a simple layer upon Webpack to help make many build adjustments quick and painless.

Modern mainstream defaults

Use next generation JavaScript and CSS with polyfills automatically applied to the browsers you choose to support.

Development proxy with script and style injection

A pre-configured webpack development server rewards your code changes with snappy browser updates. Generate additional style and script outputs just by adding them to a folder in the src directory.

Static site generator

Get straight to the build with a static site generator that converts twig to html.
There's also full support for CMS based sites by updating a few config values.

Minimal config files

Avoid excessive build configuration files with all config defined in webpack.mix.js.
The package.json contains browser targets and linting configs.

Build actions

src/styles

Style files are compiled to CSS and PostCss plugins provide additional transformations and optimisations.

Styles src folder


src/scripts

Script files are transpiled to vanilla JavaScript and the necessary polyfills included.

Script src folder

  • Script transpiling with Babel with minifying and sourcemaps
  • Automatic browser polyfills are provided by Core-Js 3
  • ESLint is provided for error linting

src/images

Images are optimized and copied to the build directory.

Image src folder

  • Optimisations are provided by Imagemin

src/icons

Individual SVG icons are optimised then combined into a single cacheable SVG.

Icons src folder

  • An async script adds the svg sprite to your page
  • You can display an icon like this:
<svg><use xlink:href="icon-code" /></svg>

src/static

Additional folders with no transform requirements are copied to your build folders.

Static src folder


Getting started

1. Copy this repo into a new project folder:

npx degit ben-rogerson/agency-webpack-mix-config new-project

โ€ฆor use Github's new tool to create a new repository then clone the project down.

2. Install the dependencies:

cd new-project && npm install

3. Update the proxy domain and start adding project files

This config allows for either static or dynamic template sites. Dynamic template sites could be ones running Craft, Wordpress, or Laravel.

a) Create a static site

This option converts the Twig templates in src/templates into static Html files and hashes assets during a production build.

  1. Update the devProxyDomain in webpack.mix.js, eg:

    const config = {
      // ...
      devProxyDomain: "http://my-static-site.test",
    }
  2. Then add your devProxyDomain to Valet/Homestead/Vagrant. If you're using Valet you can add it like this:

    cd web && valet link my-static-site.test

    You'll need to run npm run build to preview your static site operating at my-static-site.test.

  3. npm run dev to start your development server.

b) Create a dynamic site

This option lets you use a CMS and during production it compresses and hashes assets and creates a manifest file.

You could add any CMS but in this example I'll copy in the files from the Craft CMS starter:

npx degit --force craftcms/craft

Craft CMS requires a templates directory in the base folder for their twig templates so I'll add these config values in webpack.mix.js:

const config = {
    // Dev domain to proxy
    devProxyDomain: "http://my-craft-site.test",
    // Paths to observe for changes
    devWatchPaths: ["templates"],
    // Folders where purgeCss can look for used selectors
    purgeCssGrabFolders: ["src", "templates"],
    // Build a static site from the src/template files
    buildStaticSite: false,
}

Then create a new project database, add the devProxyDomain to Valet/Homestead/Vagrant and finish the Craft install with composer install && ./craft setup.

Loading the files from the manifest

No matter what CMS you use, you'll need a way to reference the files from the mix-manifest.json file that's created. This example shows how to use Twigpack to load the files from the manifest.

Removing excess packages

There will be some unnecessary packages used only for rendering a static site. Remove them from your project:

npm rm html-webpack-plugin twig-html-loader laravel-mix-twig-to-html

Tasks

The following tasks are available:

npm run dev
# Run the development server

npm run start
# Run the development build

npm run build
# Run the production build

npm run fix-scripts
# Fix your javascript with eslint

More Repositories

1

twin.macro

๐Ÿฆนโ€โ™‚๏ธ Twin blends the magic of Tailwind with the flexibility of css-in-js (emotion, styled-components, solid-styled-components, stitches and goober) at build time.
TypeScript
7,882
star
2

twin.examples

Packed with examples for different frameworks, this repo helps you get started with twin a whole lot faster.
TypeScript
463
star
3

babel-plugin-twin

Activate twin.macroโ€™s tw prop without adding the twin import. A companion plugin for twin.
JavaScript
41
star
4

mezz

๐Ÿ“๐Ÿ‘๏ธ React hooks for building responsive and adaptable web interfaces
TypeScript
33
star
5

nuxt-seomatic-meta

A module for connecting Nuxt.js to the Craft CMS SEOmatic plugin via GraphQL. Nuxt-o-matic!
JavaScript
30
star
6

laravel-mix-make-file-hash

๐Ÿ“‘ Convert Laravel Mix querystring hashing to filename hashing. Eg: main.css?id=abcd1234 to main.abcd1234.css
JavaScript
12
star
7

laravel-mix-twig-to-html

A Laravel Mix extension to convert Twig files to Html
JavaScript
9
star
8

twin.site

The documentation website for twin.macro
JavaScript
9
star
9

starred-repositories

โญ Generate a static site of your starred Github repositories.
JavaScript
6
star
10

craft-gulp

๐ŸŽจ Craft CMS + SCSS + JS + Gulp > A full set of build-tools for Craft website developers
JavaScript
3
star
11

server-communication-examples

A collection of examples for communicating with a backend server.
TypeScript
3
star
12

zshconfig

๐Ÿค“ My ZSH config for 2020
Shell
2
star
13

iconish

๐Ÿ‘๏ธ Align and minify your SVG icon sets for the web
TypeScript
2
star
14

bemgen

๐Ÿค˜Quickly generate HTML & CSS code from a component structure.
JavaScript
1
star
15

laravel-typescript-react-tailwind-twin

1
star
16

DripWave

๐Ÿ’ง Search for artists and preview their music
TypeScript
1
star
17

FlipTrend

View stocks by country, sorted by market cap
TypeScript
1
star