Coder Social home page Coder Social logo

mizziness / craft3-webpack5-tailwind2-boilerplate Goto Github PK

View Code? Open in Web Editor NEW
44.0 3.0 11.0 1.5 MB

A real-world boilerplate for Craft CMS 3 projects that leverages Wepback 5, Tailwind 2, PostCSS 8, and has a hot-reload dev environment. Now with dynamic imports, asynchronous chunk loading, and legacy vs modern browser support!

License: MIT License

Shell 1.74% PHP 25.40% JavaScript 54.30% SCSS 7.55% Twig 11.01%
webpack-dev-server webpack boilerplate babel postcss tailwindcss core-js hmr

craft3-webpack5-tailwind2-boilerplate's Introduction

Craft CMS 3 Boilerplate

(with Webpack 5, Tailwind 2, PostCSS 8, and HMR, and other goodies)

A real-world boilerplate for Craft CMS 3 projects that leverages Wepback 5, Tailwind 2, PostCSS 8, and Twigpack. Also included is a hot-reload dev environment. I created this as a starting point for Craft CMS 3 / Webpack 5 projects.

What's New

This version of the project has a few significant changes, including updates to the framework and dependencies, better bundle performance in production, better asset chunking and support, and a starting point for your template structure.

What's Included

  • Craft CMS 3 - My CMS of choice, and the app which will consume assets from Webpack.
  • Webpack 5 - Bundling, optimizing, and serving your assets
  • Twigpack - The bridge between Craft CMS and Webpack
  • TailwindCSS 2 - Awesome CSS framework that makes dev speedy
  • SASS - SASS/SCSS Support
  • PostCSS - Post-processing CSS Files

Other included tools/plugins

Webpack

Transpiling

Loaders, Sass, Plugins

Get Started

First, finish up installing Craft CMS locally for your development environment. The setup wizard will take you through providing your database credentials, and will also generate a new security key and App ID.

$ composer install
$ ./craft setup/index

Then install our other packages and run the HMR development server:

$ yarn install
$ yarn dev

(I use yarn for my project, but you don't need to - use the tool of your choice.)

Webpack assets are set up to serve from https://localhost:8080 by default.

Note: The URL "https://localhost:8080" won't show anything by default, but if you prefer to have a page load, you can edit wpconfig/webpack.dev.js and uncomment the new HtmlWebpackPlugin code block. This will generate an index.html file along with your assets.

You can include your chunked/hashed assets in Craft CMS templates by using Twigpack's features:

{{ craft.twigpack.includeCssModule("app.css", true) }}
{{ craft.twigpack.includeJsModule("app.js", true, {"type": "module"}) }}
{{ craft.twigpack.includeJsModule("chunk-vendors.js", true) }}

If you open up the included templates/index.twig file, you'll see that it has been edited to support Twigpack and our bundles.

Scripts

As you can see in the package.json file, there are 3 included scripts for convenience:

clean": "./craft clear-caches/all && ./craft cache/flush-all", "clean:dist": "rm -rf ./web/dist/*", "clean:all": "yarn run clean:dist && yarn run clean", "dev": "yarn run clean:dist && cross-env NODE_ENV=development --max_old_space_size=8096 webpack serve --mode development --config ./wpconfig/webpack.dev.js", "build": "yarn run clean:dist && cross-env NODE_ENV=production webpack --mode production --config ./wpconfig/webpack.prod.js", "stats":

  • yarn dev - Runs the HMR development server
  • yarn build - Creates a production-ready build for deployment (asset output is in web/dist)
  • yarn clean - A quick way to clear Craft CMS caches while you code
  • yarn clean:dist - Clean out the the local build cache folder, web/dist
  • yarn clean:all - Clean both the Craft CMS cache and the local build cache folder

Make it Yours

This project comes pre-configured out of the box to work with Craft CMS templates, but there are plenty of ways you can customize the way this works to suit your own needs. It tries to make few assumptions about your toolkit, other than the minimum required configuration to work with the tools included.

  • Tailwind has been set up with with a default configuration, and I highly suggest modifying it for your project. (You can overwrite it with an existing tailwind.config.js file, if you have one, to import all your custom styling quickly.)
  • devServer options can be changed and extended as needed - for example, by default auto open for the served url is turned off, but if you're using a custom generated template, then you might want it on, instead.
  • Go to town!

Prettier Webpack

If you're like me and you prefer a cleaner webpack report, try this:

yarn add webpackbar -D

In the wpconfig files, you'll see two commented-out lines which you can uncomment to enable a much nicer view of your webpack report with webpackbar.

Inspired By

And used as a starting point: https://github.com/taniarascia/webpack-boilerplate

License

This project is open source and available under the MIT License.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.