npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@appnest/web-config

v0.5.4

Published

A Rollup configuration to help you build modern web applications.

Downloads

494

Readme

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

➤ 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? |

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

➤ License

Licensed under MIT.