Skip to content

Commit 20fa897

Browse files
committed
build: handle ts build
1 parent f6d3f28 commit 20fa897

File tree

13 files changed

+509
-42
lines changed

13 files changed

+509
-42
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ dist
66
lerna-debug.log
77
yarn-error.log
88
packages/*/*.tgz
9+
.rpt2_cache

package.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,16 @@
2020
"eslint-config-prettier": "^6.0.0",
2121
"eslint-plugin-prettier": "^3.1.0",
2222
"lerna": "^3.15.0",
23-
"prettier": "^1.18.2"
23+
"prettier": "^1.18.2",
24+
"rimraf": "^2.6.3",
25+
"rollup": "^1.16.7",
26+
"rollup-plugin-alias": "^1.5.2",
27+
"rollup-plugin-commonjs": "^10.0.1",
28+
"rollup-plugin-node-resolve": "^5.2.0",
29+
"rollup-plugin-replace": "^2.2.0",
30+
"rollup-plugin-strip-banner": "^0.2.0",
31+
"rollup-plugin-terser": "^5.1.1",
32+
"rollup-plugin-typescript2": "^0.22.0"
2433
},
2534
"scripts": {
2635
"prerelease": "lerna version -m 'chore(release): publish'",

packages/@posva/vuefire-core/declarations.d.ts

Lines changed: 0 additions & 6 deletions
This file was deleted.

packages/@posva/vuefire-core/package.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,18 @@
55
"author": "Eduardo San Martin Morote <[email protected]>",
66
"homepage": "https://github.com/vuejs/vuefire#readme",
77
"license": "MIT",
8-
"main": "src/index.ts",
8+
"sideEffects": false,
9+
"main": "dist/vuefire-core.cjs.js",
10+
"types": "dist/packages/@posva/vuefire-core/src",
11+
"browser": "dist/vuefire-core.esm.js",
12+
"module": "dist/vuefire-core.esm.js",
913
"directories": {
1014
"lib": "src",
1115
"test": "test"
1216
},
1317
"files": [
1418
"src",
19+
"dist",
1520
"LICENSE"
1621
],
1722
"publishConfig": {
@@ -24,6 +29,8 @@
2429
"scripts": {
2530
"pretest": "yarn run lint",
2631
"test": "yarn run test:unit",
32+
"build": "rollup -c ../../../rollup.config.js",
33+
"postversion": "yarn run build",
2734
"test:unit": "jest",
2835
"lint": "eslint --fix src __tests__ --ext ts",
2936
"dev": "yarn run test:unit --watchAll"

packages/@posva/vuefire-core/src/firestore/index.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -305,15 +305,10 @@ interface BindDocumentParamater extends CommonBindOptionsParameter {
305305
document: firestore.DocumentReference
306306
}
307307

308-
/* TODO do not use an object
309-
*
310-
* @param {*} vm
311-
* @param {string} key
312-
* @param {firebase.firestore.DocumentReference} document
313-
* @param {*} resolve
314-
* @param {*} reject
315-
* @param {OperationsType<any>} ops
316-
* @param {*} options
308+
/**
309+
* Binds a Document to a property of vm
310+
* @param param0
311+
* @param extraOptions
317312
*/
318313
export function bindDocument(
319314
{ vm, key, document, resolve, reject, ops }: BindDocumentParamater,
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"extends": "../../../tsconfig.json",
3+
"include": ["src"],
4+
"compilerOptions": {
5+
"target": "esnext",
6+
"module": "esnext",
7+
"noEmit": false,
8+
"strict": true,
9+
"composite": true,
10+
"esModuleInterop": true,
11+
"moduleResolution": "node",
12+
"outDir": "dist"
13+
}
14+
}

packages/vuefire/jest.config.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
module.exports = {
2+
preset: 'ts-jest',
23
collectCoverage: true,
3-
collectCoverageFrom: ['<rootDir>/src/**/*.js'],
4+
collectCoverageFrom: ['<rootDir>/src/**/*.ts'],
5+
testMatch: ['<rootDir>/__tests__/**/*.spec.ts'],
6+
testEnvironment: 'node',
47
testURL: 'http://localhost/',
58
}

packages/vuefire/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"module": "dist/vuefire.esm.js",
77
"unpkg": "dist/vuefire.js",
88
"browser": "dist/vuefire.esm.js",
9-
"types": "types/index.d.ts",
9+
"types": "dist/packages/vuefire/src",
1010
"sideEffects": false,
1111
"files": [
1212
"dist",
@@ -21,7 +21,7 @@
2121
"test:unit": "jest",
2222
"types": "tsc -p ./types/test/tsconfig.json",
2323
"dev": "yarn run test:unit --watchAll",
24-
"build": "node --eval 'require(\"@posva/vuefire-bundler\")(\"Vuefire\")'",
24+
"build": "rollup -c ../../rollup.config.js",
2525
"postversion": "yarn run build"
2626
},
2727
"repository": {

packages/vuefire/tsconfig.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"extends": "../../tsconfig.json",
3+
"include": ["src"],
4+
"compilerOptions": {
5+
"target": "es5",
6+
"module": "esnext",
7+
"noEmit": false,
8+
"strict": true,
9+
"composite": true,
10+
"esModuleInterop": true,
11+
"moduleResolution": "node",
12+
"outDir": "dist"
13+
}
14+
}

rollup.config.js

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
import replace from 'rollup-plugin-replace'
2+
import resolve from 'rollup-plugin-node-resolve'
3+
import commonjs from 'rollup-plugin-commonjs'
4+
import ts from 'rollup-plugin-typescript2'
5+
import alias from 'rollup-plugin-alias'
6+
import stripBanner from 'rollup-plugin-strip-banner'
7+
import { terser } from 'rollup-plugin-terser'
8+
import path from 'path'
9+
import rimraf from 'rimraf'
10+
11+
const cwd = process.cwd()
12+
// eslint-disable-next-line
13+
const pkg = require(path.join(cwd, 'package.json'))
14+
15+
rimraf.sync(path.join(cwd, './dist'))
16+
17+
const banner = `/*!
18+
* ${pkg.name} v${pkg.version}
19+
* (c) ${new Date().getFullYear()} Eduardo San Martin Morote
20+
* @license MIT
21+
*/`
22+
23+
const firstLetter = pkg.name[0]
24+
const exportName =
25+
firstLetter !== '@' ? firstLetter.toUpperCase() + pkg.name.slice(1) : 'VuefireCore'
26+
27+
function createEntry(
28+
{
29+
format, // Rollup format (iife, umd, cjs, es)
30+
external, // Rollup external option
31+
input = 'src/index.ts', // entry point
32+
env = 'development', // NODE_ENV variable
33+
minify = false,
34+
isBrowser = false, // produce a browser module version or not
35+
} = {
36+
input: 'src/index.ts',
37+
env: 'development',
38+
minify: false,
39+
isBrowser: false,
40+
}
41+
) {
42+
// force production mode when minifying
43+
if (minify) env = 'production'
44+
45+
const config = {
46+
input,
47+
plugins: [
48+
replace({
49+
__VERSION__: pkg.version,
50+
'process.env.NODE_ENV': `'${env}'`,
51+
}),
52+
alias({
53+
resolve: ['ts'],
54+
consola: path.resolve(__dirname, './src/consola.ts'),
55+
firebase: path.resolve(__dirname, './stub.ts'),
56+
}),
57+
],
58+
output: {
59+
banner,
60+
file: `dist/${pkg.name}.UNKNOWN.js`,
61+
format,
62+
},
63+
}
64+
65+
if (format === 'iife') {
66+
config.output.file = pkg.unpkg
67+
config.output.name = exportName
68+
} else if (format === 'es') {
69+
config.output.file = isBrowser ? pkg.browser : pkg.module
70+
} else if (format === 'cjs') {
71+
config.output.file = pkg.main
72+
}
73+
74+
if (!external) {
75+
config.plugins.push(
76+
resolve(),
77+
commonjs(),
78+
// avoid duplicated banners when reusing packages
79+
stripBanner({
80+
include: path.join(__dirname, './packages/**/*.js'),
81+
})
82+
)
83+
} else {
84+
config.external = external
85+
}
86+
87+
config.plugins.push(
88+
ts({
89+
// only check once, during the es version with browser (it includes external libs)
90+
check: format === 'es' && isBrowser && !minify,
91+
tsconfigOverride: {
92+
compilerOptions: {
93+
// same for d.ts files
94+
declaration: format === 'es' && isBrowser && !minify,
95+
target: format === 'iife' || format === 'cjs' ? 'es5' : 'esnext',
96+
},
97+
},
98+
})
99+
)
100+
101+
if (minify) {
102+
config.plugins.push(
103+
terser({
104+
module: format === 'es',
105+
output: {
106+
preamble: banner,
107+
},
108+
})
109+
)
110+
config.output.file = config.output.file.replace(/\.js$/i, '.min.js')
111+
}
112+
113+
return config
114+
}
115+
116+
const builds = [createEntry({ format: 'cjs' }), createEntry({ format: 'es', isBrowser: true })]
117+
118+
if (pkg.unpkg)
119+
builds.push(
120+
createEntry({ format: 'iife' }),
121+
createEntry({ format: 'iife', minify: true }),
122+
createEntry({ format: 'es', isBrowser: true, minify: true })
123+
)
124+
125+
export default builds

stub.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
const database = {}
2+
export { database }

tsconfig.json

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,7 @@
99
"moduleResolution": "node",
1010

1111
"rootDir": ".",
12-
"baseUrl": ".",
13-
"paths": {
14-
// "vue": ["./node_modules/vue"],
15-
// "@posva/vuefire-core": ["./packages/@posva/vuefire-core/src"],
16-
// "@posva/vuefire-test-helpers": ["./packages/@posva/vuefire-test-helpers/src"]
17-
// "vuef": ["./packages/@posva/vuefire-test-helpers"],
18-
}
12+
"baseUrl": "."
1913
},
2014
"include": [
2115
"packages/global.d.ts",

0 commit comments

Comments
 (0)