Skip to content

Commit 1546e2c

Browse files
author
Vasilii Kovalev
authored
Make CJS and UMD builds (#12)
* Add Webpack and write a config to create UMD builds * Make Webpack building normal and minified UMD builds * Add TS configs for CJS (tsconfig.node.json) and UMD (tsconfig.webpack.json) builds * Write some scripts to create different builds * Update .eslintrc and up its version * Update dependencies * Up library version to 1.2.0
1 parent dc871da commit 1546e2c

File tree

8 files changed

+3591
-204
lines changed

8 files changed

+3591
-204
lines changed

.eslintrc

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
// "version": "1.0.0",
2+
// "version": "1.1.0",
33
"plugins": [
44
"@typescript-eslint"
55
],
@@ -70,6 +70,14 @@
7070
"ts": "never"
7171
}
7272
],
73+
"import/no-extraneous-dependencies": [
74+
"error",
75+
{
76+
"devDependencies": [
77+
"webpack.config.ts"
78+
]
79+
}
80+
],
7381
"import/prefer-default-export": "off"
7482
},
7583
"parser": "@typescript-eslint/parser",

package-lock.json

Lines changed: 3494 additions & 190 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"name": "hydrate-text",
3-
"version": "1.1.5",
3+
"version": "1.2.0",
44
"description": "Tiny library for dynamic text hydrating with variables",
5-
"main": "lib/index",
6-
"module": "lib/index",
7-
"types": "lib/index.d.ts",
5+
"main": "./dist/cjs/index.js",
6+
"module": "./dist/esm/index.js",
7+
"types": "./dist/typings/index.d.ts",
88
"sideEffects": false,
99
"keywords": [
1010
"javascript",
@@ -26,22 +26,38 @@
2626
"url": "https://github.com/vasilii-kovalev/hydrate-text/issues"
2727
},
2828
"devDependencies": {
29-
"@types/jest": "^26.0.5",
29+
"@types/jest": "^26.0.7",
30+
"@types/node": "^14.0.26",
31+
"@types/terser-webpack-plugin": "^3.0.0",
32+
"@types/webpack": "^4.41.21",
3033
"@typescript-eslint/eslint-plugin": "^3.7.0",
3134
"@typescript-eslint/parser": "^3.7.0",
35+
"babel-core": "6.26.3",
36+
"babel-loader": "8.1.0",
37+
"cross-env": "^7.0.2",
3238
"eslint": "^7.5.0",
3339
"eslint-config-airbnb-base": "^14.2.0",
3440
"eslint-plugin-import": "^2.22.0",
3541
"husky": "^4.2.5",
3642
"jest": "^26.1.0",
43+
"terser-webpack-plugin": "^3.0.7",
3744
"ts-jest": "^26.1.3",
38-
"typescript": "^3.9.7"
45+
"ts-node": "^8.10.2",
46+
"tsconfig-paths": "^3.9.0",
47+
"typescript": "^3.9.7",
48+
"webpack": "4.44.0",
49+
"webpack-cli": "3.3.12"
3950
},
4051
"scripts": {
4152
"test": "jest",
4253
"tslint": "tsc --noEmit",
43-
"eslint": "eslint --ext .ts src --color",
44-
"build": "tsc",
54+
"eslint": "eslint --ext .ts src webpack.config.ts --color",
55+
"build:esm": "tsc -p tsconfig.json",
56+
"build:cjs": "tsc -p tsconfig.node.json",
57+
"build:umd": "cross-env TS_NODE_PROJECT=\"tsconfig.webpack.json\" webpack",
58+
"build:umd:min": "npm run build:umd -- --env.MINIMIZE",
59+
"prebuild": "npm run build:esm && npm run build:cjs",
60+
"build": "npm run build:umd && npm run build:umd:min",
4561
"prepare": "npm run build",
4662
"prepublishOnly": "npm run tslint && npm run eslint && npm test",
4763
"postversion": "git push && git push --tags"

tsconfig.eslint.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
{
2-
"version": "1.0.0",
2+
"version": "1.0.1",
33
"extends": "./tsconfig.json",
44
"exclude": [],
55
"include": [
6-
"src"
6+
"src",
7+
"webpack.config.ts"
78
],
89
"compilerOptions": {
910
"noEmit": true

tsconfig.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
{
2-
"version": "1.0.0",
32
"exclude": [
43
"node_modules",
54
"src/**/*.test.ts",
6-
"lib/*"
5+
"dist/*"
76
],
7+
// Without "include" TypeScript tries to compile "webpack.config.ts" as well.
8+
"include": ["src"],
89
"compilerOptions": {
910
/* Basic Options */
1011
// "incremental": true,
@@ -15,10 +16,11 @@
1516
// "checkJs": true,
1617
// "jsx": "preserve",
1718
"declaration": true,
19+
"declarationDir": "./dist/typings/",
1820
// "declarationMap": true,
1921
// "sourceMap": true,
2022
// "outFile": "./",
21-
"outDir": "./lib",
23+
"outDir": "./dist/esm/",
2224
"rootDir": "src",
2325
// "composite": true,
2426
// "tsBuildInfoFile": "./",

tsconfig.node.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"compilerOptions": {
4+
"target": "es5",
5+
"module": "commonjs",
6+
"outDir": "./dist/cjs/",
7+
}
8+
}

tsconfig.webpack.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"compilerOptions": {
3+
"module": "commonjs",
4+
"target": "es5",
5+
"esModuleInterop": true
6+
}
7+
}

webpack.config.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import path from 'path';
2+
3+
import TerserPlugin from 'terser-webpack-plugin';
4+
import { ConfigurationFactory } from 'webpack';
5+
6+
const configurationFactory: ConfigurationFactory = env => {
7+
const parsedMinimize = typeof env === 'string'
8+
? false
9+
: env?.MINIMIZE;
10+
const minimize = Boolean(parsedMinimize);
11+
12+
return {
13+
mode: 'production',
14+
entry: {
15+
index: path.resolve(__dirname, './dist/esm/index.js'),
16+
},
17+
output: {
18+
path: path.resolve(__dirname, './dist/umd'),
19+
filename: `[name]${minimize ? '.min' : ''}.js`,
20+
library: 'hydrateText',
21+
libraryTarget: 'umd',
22+
globalObject: 'this',
23+
},
24+
module: {
25+
rules: [
26+
{
27+
test: /\.t|js$/,
28+
use: 'babel-loader',
29+
},
30+
],
31+
},
32+
optimization: {
33+
minimize,
34+
minimizer: [
35+
new TerserPlugin(),
36+
],
37+
},
38+
};
39+
};
40+
41+
module.exports = configurationFactory;

0 commit comments

Comments
 (0)