Giter Site home page Giter Site logo

tr1s / tris-webpack-boilerplate Goto Github PK

View Code? Open in Web Editor NEW
1.0K 25.0 99.0 19.79 MB

A Webpack boilerplate for static websites that has all the necessary modern tools and optimizations built-in. Score a perfect 10/10 on performance.

Home Page: https://twbp.tris.codes/

License: MIT License

HTML 20.31% JavaScript 36.07% SCSS 43.62%
webpack webpack-boilerplate optimization babel es6 starter boilerplate webpack4 sass scss

tris-webpack-boilerplate's Introduction

Note: This project is no longer actively maintained.

Unfortunately, I don't have the time/enthusiasm to maintain this project right now. I recommend forking this project, or reading its source to learn how it's built.


tris-webpack-boilerplate

Build Status Dependencies Status Dev Dependencies Status Twitter Badge License Badge Donate Badge

Google Lighthouse Report

This webpack boilerplate is for beginner, intermediate, and advanced developers looking to create static websites quickly while acheiving all the right optimizations to score perfect on Google Page Speed Insights and Google Lighthouse Reports β€” This is an evolution of tris-gulp-boilerplate, now with Webpack 4. Webpack is the new standard for bundling JS which Gulp wasn't capable of. Thankfully Webpack can both run tasks and bundle js πŸ’ͺ

The goal of this project/boilerplate is to reach the following people:

  1. The beginners πŸ‘Ά β€” who although use Gulp/Webpack/Node/Npm still need more thorough explainations than the more acquainted developers. They want things to work, but they want to know how and why as well.
  2. The side-project hustlers πŸƒβ€β™€οΈ β€” those with all the great ideas but don't want to waste time with setup. They need to get their ideas, apps, and websites out and into the browser... fast.
  3. The obsessive compulsive πŸ•΅οΈβ€β™‚οΈ β€” people who love getting those perfect scores on performance and optimizaitons reports. People who are digitally organized and pride themselves knowing that all their files are minimized, compressed, zipped, and ready to ship!

Feel free to fork this repo and create your own workflow based off this template! Everyone's a little different, I understand.


Usage

You need git and node.js on your computer before running.

  1. git clone https://github.com/tr1s/tris-webpack-boilerplate.git your-project-name
  2. cd your-project-name && rm -rf .git
  3. npm install
  4. npm start

You're all set, start coding πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’» !

Remove everything in the src/styles/ folder, src/index.html and src/index.scss/ if you'd like to start 100% fresh and/or create your own Sass worklow. I based my folder structure off the 7-1 pattern.

  1. npm run build when you're ready to upload your site to your FTP / hosting platform of choice. This will create a dist folder with all your website assets optimized and compressed.

If you'd like an in-depth explaination as to how everything works, please read about the features below. Otherwise, carry on coding and have fun :)





Features / Contents


Features Explained

Webpack Config Split

Instead of having one big webpack.config.js, we'll split our production and development builds into two new configs called webpack.dev.js and webpack.prod.js. Configurations we want on both development and production will go in the webpack.common.js config.

When we run npm start, it will run the development build based off the webpack.dev.js config which also has the merged webpack.common.js configurations. Read more about this in the Webpack documentation.

/* wenpack.dev.js */

const merge = require("webpack-merge");
const common = require("./webpack.common.js");

/* merges the webpack.common.js and then you add your extra */

module.exports = merge(common, {
  mode: "development",
  /* the rest of code goes here */
});

When we run npm run build, it will run the production build based off the webpack.prod.js config which also has the merged webpack.common.js configurations.

/* webpack.prod.js */

const merge = require("webpack-merge");
const common = require("./webpack.common.js");

/* merges the webpack.common.js and then you add your extra */

module.exports = merge(common, {
  mode: "production",
});

We want our development and production builds to produce the same results visually in the browser. You don't want to finish coding, run the build, and then have a totally different website on build with missing images for example. That's why we have webpack.common.js to handle all the loaders and asset management. The webpack.dev.js will be slightly different with a lighter weight sourcemap. Finally the webpack.prod.js will handle all the final stages of getting your website to production. That being image compression, asset compression (gzip), asset minification, favicon generation, caching, and creating an offline-first experience.

I'll go into each process below.


Webpack Development Server

The webpack-dev-server is configured in the package.json. npm start will run the server and open your project in the browser using the webpack.dev.js config. npm start is npm's default script, so you don't need to add run to it. But for the build script you need to type npm run build.

"scripts": {
  "start": "webpack-dev-server --open --config webpack.dev.js",
  "build": "webpack --config webpack.prod.js"
},


HTML assets and minification

We use the html-loader to export HTML as a string and minify the output. This allows you to import your src/index.html within your src/index.js. We can simply minify the HTML with a loader option minimize: true, so this is why we leave it in the webpack.common.js instead of moving it to webpack.prod.js.

/* webpack.common.js */

{
  test: /\.html$/,
  use: [{
    loader: 'html-loader',
    options: {
      minimize: true
    }
  }]
},
/* src/index.js */

import "./index.html";

We then use html-webpack-plugin to create a new generated index.html with all the correct asset imports.

The template: option is where you're pulling your source HTML from. You can use your own html template, handlebars template, or any of these other templates.

The inject: option is where your assets will go. Webpack will put your bundled webpack-bundle.js script at the bottom of the body by default, but here I switched it to head because we'll be using the script-ext-html-webpack-plugin to add a defer attribute to the script and place it in the head of the website. This helps with performance.

/* webpack.common.js */

const HtmlWebpackPlugin = require('html-webpack-plugin');
const ScriptExtHtmlWebpackPlugin = require("script-ext-html-webpack-plugin");

plugins: [
  new HtmlWebpackPlugin({
    title: 'tris-webpack-boilerplate',
    filename: 'index.html',
    template: './src/index.html',
    inject: 'head'
  }),
  new HtmlWebpackPlugin({
    title: 'tris-404-page',
    filename: '404.html',
    template: './src/404.html',
    inject: 'head'
  }),
  new ScriptExtHtmlWebpackPlugin({
    defaultAttribute: 'defer'
  }),
],

Keep adding more new HtmlWebpackPlugin({}) plugins if you're going to have a multipage website. Name the page appropriately with the title: key.


404 page not found

Netlify is a fantastic free service that let's you manage and deploy your websites. Netlify automatically searches for a 404.html and will load that page when someone tries to open a broken link on your website. So there's nothing for you to worry about.

If you use a different service, please do some research on how you can link your 404.html page so that it's active. It's a great way to send people back to your main page if they land on a broken link.


SCSS to CSS + optimizations

In order to use Sass/SCSS, we need to use a few loaders to get our desired results. The css-loader, postcss-loader, and the sass-loader.

test: is using regex (regular expression) to check for any sass, scss, or css files and then runs them through these three loaders, which is wrapped around mini-css-extract-plugin, which then generates a single CSS file for you to use in production.

Read more about the concept of loaders.

/* webpack.common.js */
{
  test: /\.(sa|sc|c)ss$/,
  use: [
    MiniCssExtractPlugin.loader,
    {
      loader: 'css-loader',
      options: {
        sourceMap: true
      }
    },
    {
      loader: 'postcss-loader',
      options: {
        sourceMap: true
      }
    },
    {
      loader: 'sass-loader',
      options: {
        sourceMap: true
      }
    }
  ]
},

The second part of the loader sequence, the postcss-loader, that's where you'll be minifying and autoprefixing your css. To do this we create a postcss.config.js at the root of the project and configure it like so...

/* postcss.config.js */

const purgecss = require("@fullhuman/postcss-purgecss");

module.exports = {
  plugins: [
    require("autoprefixer"),
    require("cssnano")({
      preset: "default",
    }),
    purgecss({
      content: ["./**/*.html"],
      keyframes: true,
    }),
  ],
};

Read up on autoprefixer and cssnano to configure it more to your liking if need be. Additionally read up on postcss in general as it is a very powerful tool to have in your arsenal.

Purgecss is a fantastic postcss plugin for getting rid of unused css in your code. Purgecss analyzes your content and your css files. Then it matches the selectors used in your files with the one in your content files. It removes unused selectors from your css, resulting in smaller css files.

It's ready to go by default, but if you'd like to visually test it out for yourself, uncomment @import "../node_modules/bulma/bulma"; in index.scss, and then run npm run build and take a look at the resulting webpack-bundle.css in your dist folder. You'll notice there isn't that much code. Then remove the purgecss from your postcss.config.js and run npm run build again, you'll notice there's 10,000+ lines of code in your css coming from the Bulma framework. As you can see, purgecss is perfect for getting rid of CSS you're not using when using big frameworks like Bootstrap, Foundation, Bulma, etc!

The mini-css-extract-plugin is the final step as it extracts the CSS and gives it a name before being output.

/* webpack.common.js */

const MiniCssExtractPlugin = require("mini-css-extract-plugin");


plugins: [
  new MiniCssExtractPlugin({
    filename: 'webpack-bundle.css',
    chunkFilename: '[id].css'
  })
],

So basically... the css-loader will collect CSS from all the css files referenced in your application and put them into a string. Then postcss-loader autoprefixes and minifies your styles, then sass-loader turns it into a JS module, then mini-css-extract-plugin extracts the CSS from the JS module into a single CSS file for the web browser to parse.


ES6 transpiling

You may want to use the latest JavaScript features and syntax, but not all browsers support them yet. Babel will handle that for us.

Here we are testing for all js files but excluding the node_modules folder, then running it through the babel-loader with the babel-preset-env preset.

/* webpack.common.js */

{
  test: /\.js$/,
  exclude: /(node_modules)/,
  use: {
    loader: 'babel-loader',
    options: {
      presets: ['@babel/preset-env']
    }
  }
}

This time we're venturing into the webpack.prod.js file. When we npm run build, our output js will be minified and have full sourcemaps. Running in dev mode via npm start we'll still have lighter sourcemaps but the js will not be minified.

/* webpack.prod.js */

const TerserPlugin = require("terser-webpack-plugin");

module.exports = merge(common, {
  mode: "production",
  devtool: "source-map",
  optimization: {
    minimizer: [
      new TerserPlugin({
        test: /\.js(\?.*)?$/i,
        parallel: true,
        sourceMap: true,
      }),
    ],
  },
});

Read more about the options in the terser documentation.


Browserslist

Here we want to have one place where we can tell certain tools what browsers we'd like to add support for. We acheive this using browserslist, and the corresponding .browserslistrc file in the project root. Autoprefixer and babel-present-env will pick up on this file and apply what it needs to based on the config.

Read up on what else you can pass into .browserslistrc and use browserl.ist to see what browsers will specifically be targeted with your config. Okay I think I've said browsers enough times now 😌.

/* .browserslistrc */

> 0.25%
not dead


Image assets + compression

First we test for jpeg, jpg, png, gif, and svg using regex (regular expression), then we use file-loader, which resolves imports and requires of a file into a url then emits the file into the output directory. So if you're using an <img> element that grabs a file from the src/images folder, it will be imported and emited to the specified output path images. Which ends up being src/images if you npm start (running dev), or npm run build (running build).

/* webpack.common.js */

{
  test: /\.(jpe?g|png|gif|svg)$/,
  use: [{
    loader: 'file-loader',
    options: {
      name: '[name].[ext]',
      outputPath: 'images/',
      publicPath: 'images/'
    },
  }]
},

Now we only want to optimize our images on npm run build, so we edit our webpack.prod.js like so below.

Again we test for jpeg, jpg, png, gif, and svg using regex, and apply the appropriate optimizations. gifsicle is a lossless gif compressor, pngquant is a lossy png compressor, and we can add an extra plugin called imageminMozjpeg to perform lossy jpg/jpeg compression. A safe bet is setting the quality between 75-90 and you should get some decent compression without loss in visible quality.

I suggest sticking to the lossless compression, and cropping your images to their right size before adding to your project. Just remove the imageminMozjpeg and pngquant key sections to do so.

You can also use tinypng for image compression.

/* webpack.prod.js */

const ImageminPlugin = require("imagemin-webpack-plugin").default;
const imageminMozjpeg = require("imagemin-mozjpeg");

plugins: [
  new ImageminPlugin({
    test: /\.(jpe?g|png|gif|svg)$/i,
    gifsicle: {
      // lossless gif compressor
      optimizationLevel: 9,
    },
    pngquant: {
      // lossy png compressor, remove for default lossless
      quality: "75",
    },
    plugins: [
      imageminMozjpeg({
        // lossy jpg compressor, remove for default lossless
        quality: "75",
      }),
    ],
  }),
];


Font loading + preloading

Here we are testing for all the common font extensions and using the file-loader again to resolve our font imports and output them.

/* webpack.common.js */

{
  test: /\.(woff|woff2|ttf|otf)$/,
  use: [{
    loader: 'file-loader',
    options: {
      name: '[name].[ext]',
      outputPath: 'fonts/',
      publicPath: 'fonts/'
    },
  }]
},

In our src/styles/base/_typography.scss we are loading the fonts via the @font-face rule. Google Webfonts Helper is also a fantastic tool for self-hosting Google Fonts hassle-free. Read more about the @font-face rule on CSS-tricks. Additionally, read up on the font-display property as well.

It's always best practice to preload your fonts. We'll acheive that using the preload-webpack-plugin, and you'll need to put it right after the HtmlWebpackPlugin for it to work properly.

/* webpack.common.js */

new PreloadWebpackPlugin({
  rel: 'preload',
  as(entry) {
    if (/\.(woff|woff2|ttf|otf)$/.test(entry)) return 'font';
  },
  fileWhitelist: [/\.(woff|woff2|ttf|otf)$/],
  include: 'allAssets'
}),


Asset compression

Here we are back in the webpack.prod.js config using the compression-webpack-plugin to compress only the html, css, and javascript files. This is to avoid compressing the sourcemap files that get generated.

/* webpack.prod.js */

module.exports = merge(common, {
  mode: 'production',
  plugins: [
    new CompressionPlugin({
      test: /\.(html|css|js)(\?.*)?$/i // only compressed html/css/js, skips compressing sourcemaps etc
    }),
});


Clean Webpack Plugin

Clean-webpack-plugin is just a simple webpack plugin to remove/clean your build folder(s) before building a new one. Watch your folder scruture as you run npm run build or npm start. Your current dist folder (if you previously had one built) will be deleted and a new one will appear immediately after.

/* webpack.common.js */

const CleanWebpackPlugin = require("clean-webpack-plugin");

plugins: [new CleanWebpackPlugin(["dist"])];


Sourcemaps

Using sourcemaps is essential for debugging your code in the dev tools.

As you can see when you npm start and open up devtools in Chrome then click the console, you'll see that there are two console.logs coming from script.js line 1 and 2. We can easily see this in our folder structure at src/scripts/script.js. If we didn't use sourcemaps then devtools would show us these console.logs are coming from our bundled webpack-bundle.js, which isn't very helpful.

Similar case with our styles. If you take a look at the body element in devtools, you'll see some styles being applied from our _global.scss file, and some from our _typography.scss file, which are both located in our src/styles/base/ folder. We wouldn't be able to know this if we left out sourcemaps. It would just show us the styles came from our bundled webpack-bundle.css.

/* webpack.dev.js */

module.exports = merge(common, {
  mode: "development",
  devtool: "inline-source-map",
});
/* webpack.prod.js */

module.exports = merge(common, {
  mode: "production",
  devtool: "source-map",
});

Read up more on the different kinds of sourcemaps to find what works best for your project. Additionally read up on the devtool option in the webpack docs.


Favicon generation

This is a great plugin that generates every single icon you'll ever need based off one image source. In my src/images/ folder I have a tris-package.svg that I input into the favicons-webpack-plugin.

It will generate icons for apple, android, chrome, firefox, twitter, windows, you name it. It will generate each icon in all different sizes and import them directly into your website head where they belong. Twitter and windows are set to false but default, so I changed them to true just to cover all the bases just in-case.

Note: this dramatically increases the build time. Which is understandable considering how much it is doing under the hood and how much time it is saving you in the long run. Don't be surprised if your npm run build takes 20 seconds longer than usual.

/* webpack.prod.js */

const FaviconsWebpackPlugin = require("favicons-webpack-plugin");

module.exports = merge(common, {
  mode: "production",
  plugins: [
    new FaviconsWebpackPlugin({
      logo: "./src/images/favicon.svg",
      icons: {
        twitter: true,
        windows: true,
      },
    }),
  ],
});


Offline first and caching

Here we use the offline-plugin plugin to cache all of our assets on page load.

This plugin is intended to provide an offline experience for webpack projects. It uses ServiceWorker, and AppCache as a fallback under the hood. We simply include this plugin in our webpack.prod.js, and the accompanying runtime in our client script (src/index.js), and our project will become offline ready by caching all (or some) of the webpack output assets.

Note: If you npm run build and upload your changes to your server (or however you keep your website updated), your website will need to have been closed and re-opened before you see the changes. You can't have it open and keep refreshing, you need to close the tab and re-open it for the cache to bust.

/* webpack.prod.js */

const OfflinePlugin = require("offline-plugin");

module.exports = merge(common, {
  mode: "production",
  plugins: [new OfflinePlugin()],
});


Progressive Web App (PWA)

Progressive web applications (PWAs) are web applications that load like regular web pages or websites but can offer the user functionality such as working offline, push notifications, and device hardware access traditionally available only to native applications. PWAs combine the flexibility of the web with the experience of a native application.

The final step to make this boilerplate a PWA is to add the mandatory Web App Manifest to the root of your project and configure it appropriately!


Gotcha's

Webpack runs into issues when trying to bundle big libraries like jQuery. You'll end up with console errors like $ is not defined or jQuery is not defined. To solve this we let Webpack treat it as an external. We then define the variables and include jQuery via a CDN. Most people have jQuery cached on their browser regardless so this won't be an issue in terms of performance. I've added the externals: config by default, but you'll have to add the jQuery cdn by yourself if you plan to use it.

Read more about externals in the Webpack documentation.

/* webpack.common.js */

plugins: [],
externals: {
  $: 'jquery',
  jquery: 'jQuery',
  'window.$': 'jquery',
}
/* src/index.html */

<head>
  <script
    defer
    src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"
  ></script>
</head>


Contributing

I try my best to explain things thoroughly, but if something can be explained more clearly, please feel free to send off a pull request with some suggested edits. Thank you!


Hope this helped! Follow me on twitter if you're into that. 🌱

tris-webpack-boilerplate's People

Contributors

ayashiihito avatar biddellns avatar dependabot[bot] avatar larenelg avatar mattsroufe avatar muizzk avatar shellscape avatar shyamlohar avatar timothyvanderaerden avatar tr1s avatar

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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tris-webpack-boilerplate's Issues

Loading JS help

i'm a beginner and apologize if this is a stupid question, but I don't completely understand how to load external and local scripts.

I was trying to include https://animejs.com/ into my site. I added an import in index.js to it. but kept getting an error that anime is undefined.

I ended up just adding

<script src="https://cdnjs.cloudflare.com/ajax/libs/animejs/2.2.0/anime.js"></script>

in my index.html file, but I think this is not the correct way.

Also couldn't quite understand what I had to do to load jquery.

added this to my index.html:
<script defer src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

and this in webpack.common.js

module.exports = {
mode: 'development',
entry: './src/index.js',
externals: {
jquery: 'jQuery'
},

jquery seems to work, but i'm not sure I did it correct.

thanks

Iadn

Additional pages not loading

Hi @tr1s β€”Β thanks for sharing this, it's great.

However, I've just added an additional HTML page and when I follow the link I get the following error:
Cannot GET /services.html

Any idea why this is happening?

Thanks

No matching service worker detected

I just cloned this repo and compiled it.
Then I tested it in my GitHUB page
The problem was that the installation banner didn't appear on my Android.
Checking the site I came across the following error

Google Chrome v80 DevTool - Application - Manifest
"No matching service worker detected"

then, I added the following code in the main script file,but didn't work.
I mean I have still the above problem

 document.addEventListener('DOMContentLoaded', function() {

  if ('serviceWorker' in navigator) {

    navigator.serviceWorker.register('./sw.js').then(function(reg) {

        console.log('Successfully registered service worker', reg);

    }).catch(function(err) {

        console.warn('Error whilst registering service worker', err);

    });
    }
});

the above successful message was displayed in the console.
but the above error didn't disappear...
How can I fix this ?

can't change meta data (img, description) for sharable website url link

Hi,

I was wondering if there is an option to change meta data so when I share the link of my website I can put my own photo and description. For now I can't change it from the photo, description etc of tris-webpack-boilerplate github page. Is it put somewhere very deep? Changing meta data in index.html and other subpages doesn't change anything.

Thank you for help, Szymon :)

Can't open localhost on mobile through IP address

Hi, I'm trying to open my running server on my mobile. On mobile, in a browser, I'm writing in a following way: 192.168.178.11:8080. The website on mobile doesn't open at allβ€”the server is running all the time. Haven't had problems with this task before when using other webpacks. Thanks!

How to change to a different browser?

I have been two days now trying to figure out how to test my simple static web page in a different non-default browser.

I know it's not using the browser configured in my editor, because I changed it there, and although it does fire up that browser, it doesn't call the webpack config files correctly, so I can't do it that way.

I tried adding the following to 'webpack.dev.js' and then to 'webpack.common.js' with no luck:

  devServer: {
    open: 'Internet Explorer',
  },

I may have the browser name wrong, I tried a lot of different guesses, but I don't think it matters because it just opens Chrome anyway, no matter what I put in there.

I also tried modifying the 'run' script in 'package.json' to include 'Internet Explorer' (and tried each of the other guesses) after the '--open' parameter, but no matter what I put there, I get an error saying Windows can't find it. I even tried 'Chrome' and got the same error, so that option just won't work at all.

How is the browser being determined? How can I change it?

unused css being removed?

if i have rules in my scss that don't apply to any dom elements could it be that they aren't complied? its is a bit if a problem because i'm adding a class using JS, and the rules don't appear in the complied css file.

Preload fonts

A big detractor for rendering performance is the flash of invisible text in the period between first paint and webfonts being loaded.

This period can be reduced with <link rel="preload"> for the require web fonts, or other more complex optimizations can be achieved with fontfaceobserver, automated font subsetting, font-display etc.

To keep performance high when user start building new content from this scaffold, it would be very helpful if the template came with an already existing optimization strategy

html-loader replace

html-loader doesn't seem to replace template variables.
Things like <title><%= htmlWebpackPlugin.options.title %></title> won't work.

Any suggestions on how to make this work?

json files

Hello,

I'm using Lottie and need to refrence a json file in my script.
I tried placing it a few places in my src folder but when I preview the file I get a message that the json file cannot be found. is there something else I need to do in the config so I can use json assets?

Using Nunjuck for create stati website with multiple pages

Hello, there,

I came across this fantastic boilerplate, and I'd like to use it for my future projects. I've previously used some pre-made webpack kickstarters, but to be honest I've never dug inside the config files.

I'd like to use nunjuck as my template engine in order to output several .html files to create static websites. I used Blendid, that didn't require to manually import new .html files inside the entry js file. Is it possibile to achieve something like this?

Thank you.

Use webpack-plugin-serve instead of webpack-dev-server

Please consider trying https://github.com/shellscape/webpack-plugin-serve as an alternative to webpack-dev-server. It's leaps and bounds better in quite a few areas, much lighter, doesn't require learning a separate CLI or API, more flexible for users, and will be a lot quicker for folks especially with static sites. We've got a fairly nice feature comparison grid/notes page here: https://github.com/shellscape/webpack-plugin-serve/blob/master/.github/FEATURES.md

Probems with.eot-Files

I have to use .eot- and .svgz-font-files in mine project and get errors on npm run buid.

    ERROR in ./src/fonts/23569C_8_0.eot 1:0
    Module parse failed: Unexpected character 'οΏ½' (1:0)
    You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
    (Source code omitted for this binary file)
     @ ./src/main.scss (./node_modules/css-loader/dist/cjs.js??ref--9-1!./node_modules/postcss-loader/src??ref--9-2!./node_modules/sass-loader/dist/cjs.js??ref--9-3!./src/main.scss) 9:36-69

test: /\.(eot|woff|woff2|ttf|otf|svgz)$/, in line 37 of webpack.common.js seems to fix it.

Images are not shown on production build

Hello,

I'm using images in html with this path, there is no problem in development mode but in production these images are not shown and doesn't copy to images folder. But I have used the images in SCSS are shown and copied with 'images/xxx.svg' path.

<img src="src/images/clients/logo.png" alt="logo"/>

Do you have any idea with this?

Use woff2 and woff format fonts in example

The current use of a .ttf font in the boilerplate doesn't quite fit the objective of setting up a fast site. The .ttf-format is quite a lot heavier than .woff2 or .woff.

Current browser support is good enough that the two woff-formats cover everything you need, so the TTF can be completely removed

js-yaml vulnerabilities

Thanks again for the awesome boilerplate. I've learned so much using it!

I noticed today I'm having some dependency issues with js-yaml in the postcss-loader. I tried to fix it by updating on my own, but I'm not sure I can. The code injection vulnerability sounds particularly unfriendly.

Not sure if this is a real issue or not, but definitely curious to learn more about a fix.

Help with JS running in production after build

Hey! I'm new to Webpack as of yet, and this repo helped me a lot setting up a barebones simple project with it. I have adapted it just a bit, removed a few stuff I thought was unnecessary for now.
The issue is that my main.js file inside of <head> when in production is simply not running. It loads fine and can be reached, but nothing runs, and no error is shown on console. I have no idea how to further debug it. It runs perfectly fine on dev mode thought, which really is strange actually.

What exactly am I doing wrong? (repo here)

Enable cssnano and purgecss only for production

It looks like that purgecss is active also in development mode. That adds a computational overhead when compiling assets and it gets worse when the CSS size increases.

To solve that I change postcss.config.js as follows:

const purgecss = require('@fullhuman/postcss-purgecss')({
    content: ['./**/*.html'],
    keyframes: true
});

const cssnano = require('cssnano')({
    preset: 'default',
})

module.exports = {
    plugins: [
        require('autoprefixer'),
        ...process.env.NODE_ENV === 'production'
            ? [cssnano, purgecss]
            : []
    ]
};

And therefore also change the build command in package.json:

...

 "build": "NODE_ENV=production webpack -p --config webpack.prod.js --progress --colors",

...

it would be nice to have this in the boilerplate :)

Failed to build index.scss in production

I'm using the latest boilerplate, everything works fine in development mode, but when I try to build in production mode, I got this error :

ERROR in ./src/index.scss Module build failed (from ./node_modules/mini-css-extract-plugin/dist/loader.js): ModuleBuildError: Module build failed (from ./node_modules/postcss-loader/src/index.js): Error: The extractor has failed to extract the selectors. at Purgecss.extractSelectors (/mnt/d/Web Project/Heru/heru-port2/node_modules/purgecss/lib/purgecss.js:729:15) at Purgecss.extractFileSelector (/mnt/d/Web Project/Heru/heru-port2/node_modules/purgecss/lib/purgecss.js:662:100) at /mnt/d/Web Project/Heru/heru-port2/node_modules/@fullhuman/postcss-purgecss/lib/postcss-purgecss.js:80:37 at LazyResult.run (/mnt/d/Web Project/Heru/heru-port2/node_modules/postcss/lib/lazy-result.js:295:14) at LazyResult.asyncTick (/mnt/d/Web Project/Heru/heru-port2/node_modules/postcss/lib/lazy-result.js:208:26) at /mnt/d/Web Project/Heru/heru-port2/node_modules/postcss/lib/lazy-result.js:213:17 at runLoaders (/mnt/d/Web Project/Heru/heru-port2/node_modules/webpack/lib/NormalModule.js:316:20) at /mnt/d/Web Project/Heru/heru-port2/node_modules/loader-runner/lib/LoaderRunner.js:367:11 at /mnt/d/Web Project/Heru/heru-port2/node_modules/loader-runner/lib/LoaderRunner.js:233:18 at context.callback (/mnt/d/Web Project/Heru/heru-port2/node_modules/loader-runner/lib/LoaderRunner.js:111:13) at Promise.resolve.then.then.catch (/mnt/d/Web Project/Heru/heru-port2/node_modules/postcss-loader/src/index.js:208:9) @ ./src/index.js 13:0-22

everything is successfully built but this index.scss has failed

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.