Skip to content

Commit 05f577f

Browse files
committed
Rewrote the library to typescript.
1 parent d590d93 commit 05f577f

28 files changed

+645
-471
lines changed

README.md

+73-73
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<h1 align="center">@appnest/web-config</h1>
22
<p align="center">
3-
<a href="https://npmcharts.com/compare/@appnest/web-config?minimal=true"><img alt="Downloads per month" src="https://img.shields.io/npm/dm/@appnest/web-config.svg" height="20"/></a>
4-
<a href="https://www.npmjs.com/package/@appnest/web-config"><img alt="NPM Version" src="https://img.shields.io/npm/v/@appnest/web-config.svg" height="20"/></a>
5-
<a href="https://david-dm.org/andreasbm/web-config"><img alt="Dependencies" src="https://img.shields.io/david/andreasbm/web-config.svg" height="20"/></a>
3+
<a href="https://npmcharts.com/compare/@appnest/web-config?minimal=true"><img alt="Downloads per month" src="https://img.shields.io/npm/dm/@appnest/web-config.svg" height="20"/></a>
4+
<a href="https://www.npmjs.com/package/@appnest/web-config"><img alt="NPM Version" src="https://img.shields.io/npm/v/@appnest/web-config.svg" height="20"/></a>
5+
<a href="https://david-dm.org/andreasbm/web-config"><img alt="Dependencies" src="https://img.shields.io/david/andreasbm/web-config.svg" height="20"/></a>
66
<a href="https://github.com/andreasbm/web-config/graphs/contributors"><img alt="Contributors" src="https://img.shields.io/github/contributors/andreasbm/web-config.svg" height="20"/></a>
77
</p>
88

@@ -13,58 +13,58 @@
1313

1414
<br />
1515

16-
* An extensible `create-rollup-config.js` for using Rollup with sweet features as for example SCSS imports, Service Worker generation with Workbox, live reloading, coping resources, chunking, treeshaking, Typescript, production minifying and compression with brotli and gzip.
17-
* An extensible `create-karma-config.js` to help with your Karma testing setup
18-
* A `tsconfig.json` file to configure your Typescript
19-
* A `tslint.json` file to configure your linting
20-
* A `typings.d.ts` file to configure your typings
21-
* A `.browserslistrc` file to configure how your files are transpiled
22-
* A `.gitignore` file you can use as inspiration for your own `.gitignore` file
23-
* [`rollup-plugin-compress` - A Rollup plugin that compresses the files in the bundle after building](src/lib/rollup-plugins/compress)
24-
* [`rollup-plugin-copy` - A Rollup plugin that copies resources from one location to another](src/lib/rollup-plugins/copy)
25-
* [`rollup-plugin-html-template` - A Rollup plugin that injects the bundle entry points into a HTML file](src/lib/rollup-plugins/html-template)
26-
* [`rollup-plugin-import-styles` - A Rollup plugin that makes it possible to import style files using postcss](src/lib/rollup-plugins/import-styles)
27-
* [`rollup-plugin-live-reload` - A Rollup plugin that live reload files as they changes](src/lib/rollup-plugins/live-reload)
28-
* [`rollup-plugin-minify-lit-html` - A Rollup plugin that minifies lit-html templates](src/lib/rollup-plugins/minify-lit-html)
29-
* [`rollup-plugin-replace` - A Rollup plugin that replaces an import with another import](src/lib/rollup-plugins/replace)
30-
* [`rollup-plugin-workbox` - A Rollup plugin that uses workbox to generate a service worker](src/lib/rollup-plugins/workbox)
16+
* An extensible `create-rollup-config.js` for using Rollup with sweet features as for example SCSS imports, Service Worker generation with Workbox, live reloading, coping resources, chunking, treeshaking, Typescript, production minifying and compression with brotli and gzip.
17+
* An extensible `create-karma-config.js` to help with your Karma testing setup
18+
* A `tsconfig.json` file to configure your Typescript
19+
* A `tslint.json` file to configure your linting
20+
* A `typings.d.ts` file to configure your typings
21+
* A `.browserslistrc` file to configure how your files are transpiled
22+
* A `.gitignore` file you can use as inspiration for your own `.gitignore` file
23+
* [`rollup-plugin-compress` - A Rollup plugin that compresses the files in the bundle after building](src/lib/rollup-plugins/compress)
24+
* [`rollup-plugin-copy` - A Rollup plugin that copies resources from one location to another](src/lib/rollup-plugins/copy)
25+
* [`rollup-plugin-html-template` - A Rollup plugin that injects the bundle entry points into a HTML file](src/lib/rollup-plugins/html-template)
26+
* [`rollup-plugin-import-styles` - A Rollup plugin that makes it possible to import style files using postcss](src/lib/rollup-plugins/import-styles)
27+
* [`rollup-plugin-live-reload` - A Rollup plugin that live reload files as they changes](src/lib/rollup-plugins/live-reload)
28+
* [`rollup-plugin-minify-lit-html` - A Rollup plugin that minifies lit-html templates](src/lib/rollup-plugins/minify-lit-html)
29+
* [`rollup-plugin-replace` - A Rollup plugin that replaces an import with another import](src/lib/rollup-plugins/replace)
30+
* [`rollup-plugin-workbox` - A Rollup plugin that uses workbox to generate a service worker](src/lib/rollup-plugins/workbox)
3131
* [`rollup-plugin-budget` - A Rollup plugin that compares the sizes of the files to a specified budget](src/lib/rollup-plugins/budget)
32-
33-
[![-----------------------------------------------------](https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/vintage.png)](#table-of-contents)
34-
32+
33+
[![-----------------------------------------------------](https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/vintage.png)](#table-of-contents)
34+
3535
## ➤ Table of Contents
3636

37-
* [➤ Step 1 - Installation](#-step-1---installation)
38-
* [➤ Step 2 - Setup `rollup.config.js`](#-step-2---setup-rollupconfigjs)
39-
* [➤ Step 3 - Setup `tslint.json`](#-step-3---setup-tslintjson)
40-
* [➤ Step 4 - Setup `tsconfig.json`](#-step-4---setup-tsconfigjson)
41-
* [➤ Step 5 - Setup `.browserslistrc`](#-step-5---setup-browserslistrc)
42-
* [➤ Step 6 - Setup `karma.conf.js`](#-step-6---setup-karmaconfjs)
43-
* [➤ Step 7 - Add start and build scripts to `package.json`](#-step-7---add-start-and-build-scripts-to-packagejson)
44-
* [➤ How to load stylesheets](#-how-to-load-stylesheets)
45-
* [Add the following to your `typings.d.ts` file!](#add-the-following-to-your-typingsdts-file)
46-
* [Load a global stylesheet (it will be added to the template file)](#load-a-global-stylesheet-it-will-be-added-to-the-template-file)
47-
* [Load a stylesheet as a string](#load-a-stylesheet-as-a-string)
48-
* [➤ Contributors](#-contributors)
37+
* [➤ Step 1 - Installation](#-step-1---installation)
38+
* [➤ Step 2 - Setup `rollup.config.js`](#-step-2---setup-rollupconfigjs)
39+
* [➤ Step 3 - Setup `tslint.json`](#-step-3---setup-tslintjson)
40+
* [➤ Step 4 - Setup `tsconfig.json`](#-step-4---setup-tsconfigjson)
41+
* [➤ Step 5 - Setup `.browserslistrc`](#-step-5---setup-browserslistrc)
42+
* [➤ Step 6 - Setup `karma.conf.js`](#-step-6---setup-karmaconfjs)
43+
* [➤ Step 7 - Add start and build scripts to `package.json`](#-step-7---add-start-and-build-scripts-to-packagejson)
44+
* [➤ How to load stylesheets](#-how-to-load-stylesheets)
45+
* [Add the following to your `typings.d.ts` file!](#add-the-following-to-your-typingsdts-file)
46+
* [Load a global stylesheet (it will be added to the template file)](#load-a-global-stylesheet-it-will-be-added-to-the-template-file)
47+
* [Load a stylesheet as a string](#load-a-stylesheet-as-a-string)
48+
* [➤ Contributors](#-contributors)
4949
* [➤ License](#-license)
50-
51-
[![-----------------------------------------------------](https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/vintage.png)](#step-1---installation)
52-
50+
51+
[![-----------------------------------------------------](https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/vintage.png)](#step-1---installation)
52+
5353
## ➤ Step 1 - Installation
5454

5555
```javascript
5656
npm i @appnest/web-config --D
5757
```
5858

59-
60-
[![-----------------------------------------------------](https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/vintage.png)](#step-2---setup-rollupconfigjs)
61-
59+
60+
[![-----------------------------------------------------](https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/vintage.png)](#step-2---setup-rollupconfigjs)
61+
6262
## ➤ Step 2 - Setup `rollup.config.js`
6363

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

6666
```javascript
67-
import path from "path";
67+
import {resolve, join} from "path";
6868
import pkg from "./package.json";
6969
import {
7070
defaultExternals,
@@ -78,16 +78,16 @@ import {
7878
} from "@appnest/web-config";
7979

8080
const folders = {
81-
dist: path.resolve(__dirname, "dist"),
82-
src: path.resolve(__dirname, "src/demo"),
83-
src_assets: path.resolve(__dirname, "src/demo/assets"),
84-
dist_assets: path.resolve(__dirname, "dist/assets")
81+
dist: resolve(__dirname, "dist"),
82+
src: resolve(__dirname, "src/demo"),
83+
src_assets: resolve(__dirname, "src/demo/assets"),
84+
dist_assets: resolve(__dirname, "dist/assets")
8585
};
8686

8787
const files = {
88-
main: path.join(folders.src, "main.ts"),
89-
src_index: path.join(folders.src, "index.html"),
90-
dist_index: path.join(folders.dist, "index.html")
88+
main: join(folders.src, "main.ts"),
89+
src_index: join(folders.src, "index.html"),
90+
dist_index: join(folders.dist, "index.html")
9191
};
9292

9393
export default {
@@ -139,9 +139,9 @@ export default {
139139
}
140140
```
141141

142-
143-
[![-----------------------------------------------------](https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/vintage.png)](#step-3---setup-tslintjson)
144-
142+
143+
[![-----------------------------------------------------](https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/vintage.png)](#step-3---setup-tslintjson)
144+
145145
## ➤ Step 3 - Setup `tslint.json`
146146

147147
```json
@@ -150,9 +150,9 @@ export default {
150150
}
151151
```
152152

153-
154-
[![-----------------------------------------------------](https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/vintage.png)](#step-4---setup-tsconfigjson)
155-
153+
154+
[![-----------------------------------------------------](https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/vintage.png)](#step-4---setup-tsconfigjson)
155+
156156
## ➤ Step 4 - Setup `tsconfig.json`
157157

158158
```json
@@ -161,9 +161,9 @@ export default {
161161
}
162162
```
163163

164-
165-
[![-----------------------------------------------------](https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/vintage.png)](#step-5---setup-browserslistrc)
166-
164+
165+
[![-----------------------------------------------------](https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/vintage.png)](#step-5---setup-browserslistrc)
166+
167167
## ➤ Step 5 - Setup `.browserslistrc`
168168

169169
The tools transpiling your code are using `browserslist` to figure out what is supported. Your `.browserslistrc` could look like this.
@@ -173,9 +173,9 @@ last 2 Chrome versions
173173
last 2 Safari versions
174174
last 2 Firefox versions
175175
```
176-
177-
[![-----------------------------------------------------](https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/vintage.png)](#step-6---setup-karmaconfjs)
178-
176+
177+
[![-----------------------------------------------------](https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/vintage.png)](#step-6---setup-karmaconfjs)
178+
179179
## ➤ Step 6 - Setup `karma.conf.js`
180180

181181
```javascript
@@ -191,9 +191,9 @@ module.exports = (config) => {
191191
});
192192
};
193193
```
194-
195-
[![-----------------------------------------------------](https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/vintage.png)](#step-7---add-start-and-build-scripts-to-packagejson)
196-
194+
195+
[![-----------------------------------------------------](https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/vintage.png)](#step-7---add-start-and-build-scripts-to-packagejson)
196+
197197
## ➤ Step 7 - Add start and build scripts to `package.json`
198198

199199
Here an example on what scripts you could add to your `package.json` file.
@@ -213,9 +213,9 @@ Here an example on what scripts you could add to your `package.json` file.
213213
}
214214
```
215215

216-
217-
[![-----------------------------------------------------](https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/vintage.png)](#how-to-load-stylesheets)
218-
216+
217+
[![-----------------------------------------------------](https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/vintage.png)](#how-to-load-stylesheets)
218+
219219
## ➤ How to load stylesheets
220220

221221
### Add the following to your `typings.d.ts` file!
@@ -256,17 +256,17 @@ export default {
256256
import css from "./my-component.scss";
257257
```
258258

259-
260-
[![-----------------------------------------------------](https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/vintage.png)](#contributors)
261-
259+
260+
[![-----------------------------------------------------](https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/vintage.png)](#contributors)
261+
262262
## ➤ Contributors
263263

264-
|[<img alt="Andreas Mehlsen" src="https://avatars1.githubusercontent.com/u/6267397?s=460&v=4" width="100">](https://twitter.com/andreasmehlsen) | [<img alt="You?" src="https://joeschmoe.io/api/v1/random" width="100">](https://github.com/andreasbm/web-config/blob/master/CONTRIBUTING.md)|
265-
|:---: | :---:|
264+
|[<img alt="Andreas Mehlsen" src="https://avatars1.githubusercontent.com/u/6267397?s=460&v=4" width="100">](https://twitter.com/andreasmehlsen) | [<img alt="You?" src="https://joeschmoe.io/api/v1/random" width="100">](https://github.com/andreasbm/web-config/blob/master/CONTRIBUTING.md)|
265+
|:---: | :---:|
266266
|[Andreas Mehlsen](https://twitter.com/andreasmehlsen) | [You?](https://github.com/andreasbm/web-config/blob/master/CONTRIBUTING.md)|
267-
268-
[![-----------------------------------------------------](https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/vintage.png)](#license)
269-
267+
268+
[![-----------------------------------------------------](https://raw.githubusercontent.com/andreasbm/readme/master/assets/lines/vintage.png)](#license)
269+
270270
## ➤ License
271271

272272
Licensed under [MIT](https://opensource.org/licenses/MIT).

karma.conf.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const {defaultResolvePlugins, defaultKarmaConfig} = require("./dist/index.cjs.js");
1+
const {defaultResolvePlugins, defaultKarmaConfig} = require("./dist/lib/index.cjs.js");
22

33
module.exports = (config) => {
44
config.set({

package.json

+14-7
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,17 @@
3636
],
3737
"license": "MIT",
3838
"scripts": {
39-
"b:dev": "rollup -c --environment NODE_ENV:dev",
40-
"b:prod": "rollup -c --environment NODE_ENV:prod",
41-
"s:dev": "rollup -c --watch --environment NODE_ENV:dev",
42-
"s:prod": "rollup -c --watch --environment NODE_ENV:prod",
43-
"s": "npm run s:dev",
39+
"b:demo:dev": "rollup -c --environment NODE_ENV:dev",
40+
"b:demo:prod": "rollup -c --environment NODE_ENV:prod",
41+
"s:demo:dev": "rollup -c --watch --environment NODE_ENV:dev",
42+
"s:demo:prod": "rollup -c --watch --environment NODE_ENV:prod",
43+
"s": "npm run s:demo:dev",
44+
"b:lib": "rollup -c=rollup-lib.config.js && node post-build.js",
4445
"ncu": "ncu -u -a && npm update && npm install",
45-
"b:lib": "node build.js",
4646
"bump:patch": "npm version patch && git add . && git commit --no-edit --amend --no-verify",
4747
"bump:minor": "npm version minor && git add . && git commit --no-edit --amend --no-verify",
4848
"bump:major": "npm version major && git add . && git commit --no-edit --amend --no-verify",
49-
"publish:dist": "cd dist && npm publish --access=public && cd ..",
49+
"publish:dist": "cd dist/lib && npm publish --access=public && cd ../..",
5050
"publish:patch": "npm run bump:patch && git push && npm run b:lib && npm run publish:dist",
5151
"publish:minor": "npm run bump:minor && git push && npm run b:lib && npm run publish:dist",
5252
"publish:major": "npm run bump:major && git push && npm run b:lib && npm run publish:dist",
@@ -105,6 +105,13 @@
105105
},
106106
"devDependencies": {
107107
"@appnest/readme": "^1.1.14",
108+
"@types/escodegen": "0.0.6",
109+
"@types/esprima": "^4.0.2",
110+
"@types/estraverse": "0.0.6",
111+
"@types/filesize": "^4.1.0",
112+
"@types/fs-extra": "^5.0.5",
113+
"@types/gzip-size": "^4.1.0",
114+
"@types/node-sass": "^4.11.0",
108115
"lit-element": "^2.0.1",
109116
"lit-html": "^1.0.0",
110117
"weightless": "0.0.5"

build.js post-build.js

+3-54
Original file line numberDiff line numberDiff line change
@@ -4,42 +4,13 @@ const fs = require("fs-extra");
44
const rollup = require('rollup');
55
const pkg = require("./package.json");
66

7-
const distPath = "dist";
8-
9-
const inputOptions = (input) => {
10-
return {
11-
input,
12-
external: [
13-
...Object.keys(pkg.dependencies || {}),
14-
...Object.keys(pkg.devDependencies || {}),
15-
]
16-
}
17-
};
18-
19-
const outputOptionsEsm = (file) => {
20-
return {
21-
format: "esm",
22-
file
23-
}
24-
};
25-
26-
const outputOptionsCjs = (file) => {
27-
return {
28-
format: "cjs",
29-
file
30-
}
31-
};
7+
const distPath = "dist/lib";
328

339
/**
3410
* Builds the library.
3511
* @returns {Promise<void>}
3612
*/
37-
async function build () {
38-
39-
// Clean the dist folders
40-
await cleanDist();
41-
42-
await transpileJs();
13+
async function postBuild () {
4314

4415
// Copy the lib files
4516
await copyFiles("src/lib", distPath, [
@@ -58,28 +29,6 @@ async function build () {
5829
]);
5930
}
6031

61-
async function transpileJs () {
62-
63-
// Create the lib bundle
64-
const libBundle = await rollup.rollup({
65-
...inputOptions("./src/lib/index.js"),
66-
treeshake: false
67-
});
68-
69-
await libBundle.write(outputOptionsEsm("dist/index.esm.js"));
70-
await libBundle.write(outputOptionsCjs("dist/index.cjs.js"));
71-
}
72-
73-
/**
74-
* Cleans the dist folder.
75-
* @returns {Promise<void>}
76-
*/
77-
function cleanDist () {
78-
return new Promise((res, rej) => {
79-
rimraf(distPath, res);
80-
});
81-
}
82-
8332
/**
8433
* Copies an array of files.
8534
* @param inSrc
@@ -105,7 +54,7 @@ function copySync (src, dest) {
10554
fs.copySync(path.resolve(__dirname, src), path.resolve(__dirname, dest));
10655
}
10756

108-
build().then(_ => {
57+
postBuild().then(_ => {
10958
console.log("Done!");
11059
});
11160

0 commit comments

Comments
 (0)