All Projects → andreasbm → web-config

andreasbm / web-config

Licence: MIT license
A Rollup configuration to build modern web applications with sweet features as for example SCSS imports, Service Worker generation with Workbox, Karma testing, live reloading, coping resources, chunking, treeshaking, Typescript, license extraction, filesize visualizer, JSON import, budgets, build progress, minifying and compression with brotli a…

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language
SCSS
7915 projects
HTML
75241 projects

Projects that are alternatives of or similar to web-config

rollup-plugin-jscc
Conditional compilation and compile-time variable replacement for Rollup
Stars: ✭ 52 (+205.88%)
Mutual labels:  rollup, rollup-plugin
postcss-font-grabber
A postcss plugin, it grabs remote font files and update your CSS, just like that.
Stars: ✭ 26 (+52.94%)
Mutual labels:  rollup, rollup-plugin
rollup-plugin-tagged-template
Use plain HTML files as tagged templates.
Stars: ✭ 24 (+41.18%)
Mutual labels:  rollup, rollup-plugin
rollup-plugin-sizes
Rollup plugin to display bundle contents & size information
Stars: ✭ 77 (+352.94%)
Mutual labels:  rollup, rollup-plugin
rollup-plugin-inject-process-env
Inject environment variables in process.env with Rollup
Stars: ✭ 48 (+182.35%)
Mutual labels:  rollup, rollup-plugin
rollup-plugin-markdown
import JavaScript from Markdown code blocks
Stars: ✭ 16 (-5.88%)
Mutual labels:  rollup, rollup-plugin
rollup-plugin-generate-html-template
Rollup plugin for automatically injecting a script tag with the final bundle into an html file.
Stars: ✭ 58 (+241.18%)
Mutual labels:  rollup, rollup-plugin
rollup-plugin-collect-sass
Collect Sass, then compile
Stars: ✭ 17 (+0%)
Mutual labels:  rollup, rollup-plugin
rollup-plugin-userscript-metablock
Transform json file to userscript metablock and append on.
Stars: ✭ 26 (+52.94%)
Mutual labels:  rollup, rollup-plugin
rollup-plugin-closure-compiler-js
Rollup plugin for optimizing JavaScript with google-closure-compiler-js.
Stars: ✭ 31 (+82.35%)
Mutual labels:  rollup, rollup-plugin
rollup-plugin-external-globals
Transform external imports into global variables like output.globals.
Stars: ✭ 57 (+235.29%)
Mutual labels:  rollup, rollup-plugin
rollup-plugin-html
Import HTML files as strings in rollup build
Stars: ✭ 36 (+111.76%)
Mutual labels:  rollup, rollup-plugin
rollup-plugin-purs
Bundles PureScript modules with Rollup
Stars: ✭ 71 (+317.65%)
Mutual labels:  rollup, rollup-plugin
Preact Pwa
Super fast progressive web app with small footprint & minimal dependancies
Stars: ✭ 507 (+2882.35%)
Mutual labels:  service-worker, rollup
rollup-plugin-generate-package-json
Generate package.json file with packages from your bundle using Rollup
Stars: ✭ 29 (+70.59%)
Mutual labels:  rollup, rollup-plugin
rollup-plugin-lit-css
Moved to https://github.com/bennypowers/lit-css
Stars: ✭ 35 (+105.88%)
Mutual labels:  rollup, rollup-plugin
angular2-pokedex
A Pokedex built on Angular with AoT, Tree Shaking, Rollup and TypeScript
Stars: ✭ 34 (+100%)
Mutual labels:  rollup
zpaqfranz
Deduplicating archiver with encryption and paranoid-level tests. Swiss army knife for the serious backup and disaster recovery manager. Ransomware neutralizer. Win/Linux/Unix
Stars: ✭ 86 (+405.88%)
Mutual labels:  compression
hum2song
Hum2Song: Multi-track Polyphonic Music Generation from Voice Melody Transcription with Neural Networks
Stars: ✭ 61 (+258.82%)
Mutual labels:  web-application
drift-server
Drift server
Stars: ✭ 19 (+11.76%)
Mutual labels:  web-application

@appnest/web-config

Downloads per month NPM Version Dependencies Contributors

A Rollup configuration to help you build modern web applications.
The configuration works extremely well with the libraries lit-html and lit-element. I wanted to share it so you can use it too or build on top of it.


-----------------------------------------------------

➤ Table of Contents

-----------------------------------------------------

➤ Step 1 - Installation

The fastest way to get started is to use the CLI. Run the following command to setup your project from scratch. If you choose to use the CLI you can skip the rest of the steps in this README file.

$ npm init web-config new <dir>

To use it in your project you can install it like this.

$ npm i @appnest/web-config --D

-----------------------------------------------------

➤ Step 2 - Setup rollup.config.ts

Here's an example on what your Rollup configuration file could look like:

import {resolve, join} from "path";
import pkg from "./package.json";
import {
  defaultExternals,
  defaultOutputConfig,
  defaultPlugins,
  defaultProdPlugins,
  defaultServePlugins,
  isLibrary,
  isProd,
  isServe
} from "@appnest/web-config";

const folders = {
  dist: resolve(__dirname, "dist"),
  src: resolve(__dirname, "src/demo"),
  src_assets: resolve(__dirname, "src/demo/assets"),
  dist_assets: resolve(__dirname, "dist/assets")
};

const files = {
  main: join(folders.src, "main.ts"),
  src_index: join(folders.src, "index.html"),
  dist_index: join(folders.dist, "index.html")
};

export default {
  input: {
    main: files.main
  },
  output: [
    defaultOutputConfig({
      dir: folders.dist,
      format: "esm"
    })
  ],
  plugins: [
    ...defaultPlugins({
      copyConfig: {
        resources: [[folders.src_assets, folders.dist_assets]],
      },
      cleanerConfig: {
        targets: [
          folders.dist
        ]
      },
      htmlTemplateConfig: {
        template: files.src_index,
        target: files.dist_index,
        include: /main(-.*)?\.js$/
      },
      importStylesConfig: {
        globals: ["main.scss"]
      }
    }),

    // Serve
    ...(isServe ? [
        ...defaultServePlugins({
            dist: folders.dist
        })
    ] : []),

    // Production
    ...(isProd ? [
        ...defaultProdPlugins({
            dist: folders.dist
        })
    ] : [])
  ],
  treeshake: isProd,
  context: "window"
}

-----------------------------------------------------

➤ Step 3 - Setup .eslintrc.json

{
  "extends": "./node_modules/@appnest/web-config/eslint.js"
}

-----------------------------------------------------

➤ Step 4 - Setup tsconfig.json

{
  "extends": "./node_modules/@appnest/web-config/tsconfig.json"
}

-----------------------------------------------------

➤ Step 5 - Setup .browserslistrc

The tools transpiling your code are using browserslist to figure out what is supported. Your .browserslistrc could look like this.

last 2 Chrome versions
last 2 Safari versions
last 2 Firefox versions

-----------------------------------------------------

➤ Step 6 - Setup karma.conf.js

const {defaultResolvePlugins, defaultKarmaConfig} = require("@appnest/web-config");

module.exports = (config) => {
  config.set({
    ...defaultKarmaConfig({
      rollupPlugins: defaultResolvePlugins()
    }),
    basePath: "src",
    logLevel: config.LOG_INFO
  });
};

-----------------------------------------------------

➤ Step 7 - Add start and build scripts to package.json

Here an example on what scripts you could add to your package.json file.

{
  ...
  scripts: {
    "b:dev": "rollup -c --environment NODE_ENV:dev",
    "b:prod": "rollup -c --environment NODE_ENV:prod",
    "s:dev": "rollup -c --watch --environment NODE_ENV:dev",
    "s:prod": "rollup -c --watch --environment NODE_ENV:prod",
    "s": "npm run s:dev"
    ...
  }
  ...
}

-----------------------------------------------------

➤ Step 8 - Setup prettier.config.js

module.exports = {
   ...require("../node_modules/@appnest/web-config/rettier.config.js")
};

-----------------------------------------------------

➤ How to load stylesheets

Add the following to your typings.d.ts file!

This is to make Typescript not complaining about SCSS, CSS and JSON imports.

/// <reference path="node_modules/@appnest/web-config/typings.d.ts" />

Load a global stylesheet (it will be added to the template file)

Step 1: Import your stylesheet using the ES6 import syntax

import "./main.scss";

Step 2: Include the name of the stylesheet in your Rollup config

export default {
  ...
    defaultPlugins({
       ...
       importStylesConfig: {
         globals: ["main.scss"]
       },
       ...
    }),
  ...
}

Load a stylesheet as a string

import css from "./my-component.scss";

-----------------------------------------------------

➤ Contributors

Andreas Mehlsen You?
Andreas Mehlsen You?

-----------------------------------------------------

➤ License

Licensed under MIT.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].