lemberg / draft-theme-template

draft-theme-template
1 stars 0 forks source link
drupal drupal-8 drupal-8-theme drupal-draft drupal-theme

Draft theme template

Get started

How to organize components? Essentials.

app.scss — base entry point, a place where general styles are included. I mean styles which are fair for the whole app. That is the default entry point. ❗️Do not rename this file to keep the same base entry point per project ( and it will cause an error). Accordingly we have default corresponding Drupal library app-styles which is defined in the draft_starter.libraries.yml and applied in the draft_starter.info.yml.

src/components — the place where every component should live in an appropriate folder. There are available Atoms, Molecules, Organisms, Templates, Pages folders. The component folder could consist of

Build

build/components — the folder where transpiled results of components are living. Every component placed there in a separate folder.

build/app.css — placed in the root of build folder.

build/vendors/ — folder for vendors. Webpack set up in a way to make own vendor file in a case we have a separate vendor for the component. For example, we have slider.js where we make import of forEach nodeList polyfil. In a case only slider.js component uses forEach nodeList polyfil, you would find externals-slick.js file in a build/vendors/ folder. Then we could make a cute and tiny Drupal library. Otherwise, if a few components import forEach nodeList polyfil, you should find in the vendor folder externals.js. That means you have to make separate library externals and put it as a dependency for your both components. See examples, bellow.

We could have three types of vendors

So, for all of them behavior described above and examples provided bellow is fair.

# the only one component imports forEach nodeList polyfil
slider:
  version: 1.0
  js:
    build/vendors/externals-slider.js: {}
    build/components/slider/slider.js: {}
# a few components import forEach nodeList polyfil
slider:
  version: 1.0
  js:
    build/components/slider/slider.js: {}
  dependencies:
    - draft_starter/externals

accordion:
  version: 1.0
  js:
    build/components/accordion/accordion.js: {}
  dependencies:
    - draft_starter/externals

externals:
  version: 1.0
  js:
    build/vendors/externals.js: {}

General tips

Foundation tips

Naming folder and files and variables convention

❗️EXCEPTION, if you have a js component which is a Class — component js file should start with capital letter. For example, Slider-testimonials.js.