Skip to content

Instantly share code, notes, and snippets.

@FDiskas
Created April 7, 2020 12:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FDiskas/a367701db68f1fce2e6535976cd507f1 to your computer and use it in GitHub Desktop.
Save FDiskas/a367701db68f1fce2e6535976cd507f1 to your computer and use it in GitHub Desktop.
parcel + html + html include + scss

Steps

  1. yarn init -y
  2. yarn add -D parcel posthtml-img-autosize posthtml-include posthtml-modules autoprefixer rimraf
  3. touch .posthtmlrc.js
    module.exports = { 
        plugins: {
            "posthtml-img-autosize": {
                root: "./assets/images"
            },
            "posthtml-modules": {
                root: "./src"
            },
            "posthtml-include": {
                root: __dirname
            }
        }
    }
  4. mkdir src src/components src/pages assets assets/images
  5. touch .htmlnanorc.js
    module.exports = { 
        removeComments: false
    }
  6. touch src/index.html
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Document</title>
        <link rel="stylesheet" href="../assets/style.scss">
    </head>
    <body>
        <include src="./components/header.html"></include>
        <hr />
        Body text
        <hr />
        <include src="./components/footer.html"></include>
    </body>
    </html>
  7. Add scripts to package.json
    "scripts": {
        "start": "parcel start src/index.html",
        "build": "rimraf dist && parcel build src/index.html"
    },
  8. echo "<header>Header</header>" >> src/components/header.html
  9. echo "<footer>Header</footer>" >> src/components/footer.html
  10. echo "body { background-color: silver; }" >> assets/style.scss
  11. touch .browserslistrc
    > 1%
    last 2 versions
    

Start project

yarn start

build project

yarn build

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment