Code Monkey home page Code Monkey logo

webpack-pug-scss-boilerplate's Introduction

Webpack Pug SCSS Boilerplate

A webpack 4 based boilerplate for building web apps.

Features:

Note: There is also the feature/modern-bundle branch where webpack produces two production bundles (legacy & modern). It is experimental so use it with caution.

Usage:

  • Clone the repo via git clone https://github.com/alexnoz/webpack-pug-scss-boilerplate.git
  • cd webpack-pug-scss-boilerplate
  • Run yarn install to fetch all the dependencies
  • Run yarn start to start the webpack-dev-server (localhost:8080 will be opened automatically)
  • Start developing
  • When you are done, run yarn build to get the prod version of your app
  • If you want to analyze your production bundle, run yarn run analyze to kick off webpack-bundle-analyzer

Multiple pages:

With a few tweaks, you can use this boilerplate for multi-page apps. Suppose you have the following project structure:

app/
|-index.pug
|-index.js
|
|-about/
|   |-about.pug
|   |-index.js
|
...
  1. Make the following tweaks to the webpack.config.js:
// webpack.config.js

// ...

const commonConfig = merge([
  // ...

  plugins: [
    // 1. Remove this plugin
    new HtmlPlugin({
      template: './index.pug'
    }),
    new FriendlyErrorsPlugin(),
    new StylelintPlugin(lintStylesOptions)
  ],

  // ...
])

// ...

// 2. Call `parts.page` for each page with necessary options
const pages = [
  parts.page({
    title: 'Home',
    entry: {
      home: paths.app
    },
    template: path.join(paths.app, 'index.pug'),

    // An array of chunks to include in the page
    chunks: ['home', 'runtime', 'vendors']
  }),
  parts.page({
    title: 'About',
    path: 'about',
    entry: {
      about: path.join(paths.app, 'about')
    },
    template: path.join(paths.app, 'about/about.pug'),

    chunks: ['about', 'runtime', 'vendors']
  })
]

// ...

module.exports = env => {
  process.env.NODE_ENV = env

  const config = env === 'production'
    ? productionConfig
    : developmentConfig

  // 3. Merge these pages into the final config
  return merge(commonConfig, config, ...pages)
}

For details, please see parts.page() source and html-webpack-plugin docs.

  1. For the live reload to work, you need to include the following snippet into every index.js file (for each page):
if (process.env.NODE_ENV !== 'production') {
  require('./path/to/page.pug');
}

webpack-pug-scss-boilerplate's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

webpack-pug-scss-boilerplate's Issues

Webpack font's wrong publicPath when building

I noticed that when i tried to build anything, even a fresh clone of the repo, the fonts would never get picked up in the correct location.

This is due to the exports.loadFonts rule in webpack.parks.js needing to be changed to this:

use: {
  loader: 'file-loader',
  options:{
    publicPath:'../fonts/',
    outputPath:'fonts/',
    ...options
  }
}

I believe the issue is that @font-face SCSS serves up a relative URL that's based on where the CSS is output instead of where it's pointing during development.

How to inject stylesheet on yarn build?

Hi, first off great work on this. I'm having some trouble figuring out how to inject the compiled css stylesheet into each html file in the build process. I'm using your multi-page configuration. The css file is correctly generated at build/static/js/styles/2.a2342afa.css but there is no reference to it from any files. I've tried implementing the css-loader and file-loader in exports.extractCSS but had no luck. Any help would be great.

Cant to use multiple pages

Hi, thanks for your boilerplate, its great!
But after I have done all of the steps, the same error returns to me

image

I'm read and try by all of issues that im find here, but error alway the same
Can you help me? And how i can help for solving this problem?

Modern web development

When you install this boilerplate and do a

npm install

you end up with 154 MB of code (including node_modules dir).

Of course this is not a bug of this repository in no way. In a philosophical sense it could be seen as a question: Where did we end up with modern web development?!?!??

(Sorry, just couldn't resist. Had to post this)

Empty file, includes or extends doesn't work

I can't build pug correctly, i've try the syntaxes like these and it's not working.
Index.pug

extends layout
block main
   h1 Accueil

Layout.pug


block main
  doctype html
  html
    head
      title= "Goulgoure"
      block head
        include includes/head
    body
      block header
        include includes/header
      block content
        include includes/content
      //-scripts import 
      block scripts
        include includes/scripts

When i try to use the block at the end of file (in layout) i get the error :
Module build failed: TypeError: Cannot read property 'length' of undefined
The syntax is working correctly before with a simple pug-html-loader in webpack config.

I also need to get the template variables, how i can call these ?

Thanks for helping...

Sass(SCSS) not compiling properly in production build

Webpack doesn't seem to be compiling the SCSS properly when running the production build. When I'm running the development server everything is fine, but in production when I do basic Sass features like nesting it doesn't seem to register.

Maybe (but probably not) related: the font files give 404 errors in production. The path says /fonts/ is in /build/styles/, but it should be directly in the build folder.

After installing the modules, i did run, $ npm start . I got this error. I am on Linux Fedora 28, Node version v10.12.0

nodemon --watch webpack.config.js --exec "webpack-dev-server --open --hot --env development"

[nodemon] 1.18.4
[nodemon] to restart at any time, enter rs
[nodemon] watching: webpack.config.js
[nodemon] starting webpack-dev-server --open --hot --env development
/home/ciboz/Documents/projects/blog-website/deneme/webpack-pug-scss-boilerplate/node_modules/webpack-cli/bin/config-yargs.js:89
describe: optionsSchema.definitions.output.properties.path.description,
^

TypeError: Cannot read property 'properties' of undefined
at module.exports (/home/ciboz/Documents/projects/blog-website/deneme/webpack-pug-scss-boilerplate/node_modules/webpack-cli/bin/config-yargs.js:89:48)
at Object. (/home/ciboz/Documents/projects/blog-website/deneme/webpack-pug-scss-boilerplate/node_modules/webpack-dev-server/bin/webpack-dev-server.js:84:40)
at Module._compile (internal/modules/cjs/loader.js:688:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)
at Module.load (internal/modules/cjs/loader.js:598:32)
at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
at Function.Module._load (internal/modules/cjs/loader.js:529:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:741:12)
at startup (internal/bootstrap/node.js:285:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:739:3)
[nodemon] app crashed - waiting for file changes before starting...

Multi page tweaks not working

Hi, i can't use page function defined in the webpack.parts.js, i don't know what is the correct syntax to use it. I made 2 loop and i get a correct object. I don't know what to try anymore.

My chuncks var are in a json object wich i import with require()

Codes :
The defines of the page const

var pages = [];
var i = 1;
var j = 1;
var actual = 0;
for (i in menu){
  for (j in menu[i]) {
    var actual = menu[i][j].file;
    pages.push(
      parts.page({
        title: menu[i][j].title,
        entry: {
          home: paths.app
        },
        template: path.join(paths.app, actual + '.pug'),
        chunks: [{
          'file': actual + '.html',
          'name': menu[i][j].desc,
          'object':menu[i][j]
        }],
      })
    ); //end for + end push
  }
}

Codes at the end of webpack

return merge(commonConfig, config,...pages)

Error code

TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received type number
    at assertPath (path.js:39:11)
    at Object.resolve (path.js:1085:7)
    at HtmlWebpackPlugin.apply (/Users/loic/Desktop/Workspace/Sites/app-goulgoure/webpack-pug-scss-boilerplate/node_modules/html-webpack-plugin/index.js:50:14)

Thanks for your reply.

[Help needed] Create Blog with this boilerplate

Hello!

I'd like to create a blog with this awesome boilerplate. (I know VueJs and already created some dynamic sites with it.) I checked out this project and have it up and running.

My challenge

I have some blog posts as pug templates. Each blog post has some metadata, such as title, date and some tags. Now I need to create a start page with a list of titles of the most recent blog posts.

Metadata storage

The metadata could be stored in JSON files. I personally like to have the metadata very close to the blog post's pug source itself and not in a seperate file. (Just personal taste). So I added the metadata as a code blog at the top of the pug file that I can parse out. (Advantage: The metadata is just simple javacript and is available in the blog pug itself.

My problem

When I render the start page with webpack, this metadata needs to be available. But how do I hook into the webpack compilation process to make that data available to the pug-html-loader?

Ideas and possible aproaches

As I said, I can already parse the metadata and then have it as an array of JSON.

It is possible to pass data to the pug-html-loader. But how do I do that from within wepack?

I already managed to write a webpack plugin hooks into the webpack compiler, parses out the metadata and returns it as an array of JSONs. But how can I forward that data to the pug-html-loader from within the webpack.config.js?

Code References

My webpack.parts.js

exports.loadPug = (options) => ({
  module: {
    rules: [
      {
        test: /\.pug$/,
        use: [
          {
            loader: 'html-loader'
          },
          {
            loader: 'pug-html-loader',
            options   // <=== (B) here I can put in data that is available inside the pug templates
          }
        ]
      }
    ]
  },
  plugins: [
    new PugBlogPlugin()   // <===== (A) this webpack plugin that I wrote extracts and retuns the metadata from the blog posts
  ]
})

Sample blog post pug file

//- This is post-one just a sample post
//- the next view lines are a pug code block.
//- the metadata variable is available within this pug script
//- the JSON (between the curly brackets) will be extracted for the list of recent blogs on the start page
-
	var metadata = { 
		id: "P-1",
		title: "Post one that is long ago",
		date: "2019-08-01",
		tags: ["EINS", "ZWEI", "DREI"],
		excerpt: "The most interesting thing you always wannted to know",
	}
h1 This is my post
p
	And it can get very long 
	This is what I like very much.

How to get the data from A to B ?

Or is there a completely different aproach?

How do you make more pages?

How do you create more pages, like index.pug? I haven't used Pug much before so sorry if this should be obvious 😅

Custom fonts not working when building

I've tried starting from a completely clean repo and have a font in every possible format the loader supports. Can't get a single font to show up in the page's source when building.

I've noticed system fonts will work, which kind of gives the impression that some fonts work, but i believe something is wrong.

PUG pretty

How to make PUG pretty: true on local test env?

I dont want html inline in test environment....

I was try to use multiple pages

I did exactly the steps to use many pages but got this error

Failed to compile with 1 errors 2:19:33 PM

This dependency was not found:

  • C:\xampp\htdocs\webpack-pug-scss-boilerplate\app in multi (webpack)-dev-server/client?http://localhost:8081 (webpack)/hot/dev-server.js ./app

To install it, you can run: npm install --save C:\xampp\htdocs\webpack-pug-scss-boilerplate\app
× 「wdm」:
ERROR in Entry module not found: Error: Can't resolve 'C:\xampp\htdocs\webpack-pug-scss-boilerplate\app' in 'C:\xampp\htdocs\webpack-pug-scss-boilerplate\app'

ERROR in ./about/index.js
Module build failed (from ../node_modules/eslint-loader/index.js):
Module failed because of a eslint error.

https://google.com/#q=import%2Fno-unresolved Unable to resolve path to module '../about.pug'
app\about\index.js:4:11

https://google.com/#q=node%2Fno-missing-require "../about.pug" is not found
app\about\index.js:4:11

Problem with fresh install

➜  harper git:(feature/boostrap) ✗ npm run start

> [email protected] start /Users/pedromaia/Code/Ez/harper
> nodemon --watch webpack.config.js --exec "webpack-dev-server --open --hot --env development"

[nodemon] 1.12.1
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: webpack.config.js
[nodemon] starting `webpack-dev-server --open --hot --env development`
/Users/pedromaia/Code/Ez/harper/webpack.parts.js:67
  parts.loadPug(),
        ^

TypeError: parts.loadPug is not a function
    at Object.<anonymous> (/Users/pedromaia/Code/Ez/harper/webpack.parts.js:67:9)
    at Module._compile (module.js:569:30)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:503:32)
    at tryModuleLoad (module.js:466:12)
    at Function.Module._load (module.js:458:3)
    at Module.require (module.js:513:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/Users/pedromaia/Code/Ez/harper/webpack.config.js:13:15)
    at Module._compile (module.js:569:30)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:503:32)
    at tryModuleLoad (module.js:466:12)
    at Function.Module._load (module.js:458:3)
    at Module.require (module.js:513:17)
    at require (internal/module.js:11:18)
[nodemon] app crashed - waiting for file changes before starting...

How to use your boilerplate, it's always fail

How do you manage to get a multipage website with MIME type supported, chunks and variables in the template compiled files. Do you have a correct webpack config for that.

I'm a beginner i don't understand all of your code...
Thanks for helping.

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.