Skip to content
This repository was archived by the owner on Feb 17, 2024. It is now read-only.

Commit 5acd2a2

Browse files
committed
💣 init
0 parents  commit 5acd2a2

17 files changed

+3503
-0
lines changed

.gitignore

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
node_modules
2+
*.log
3+
*.tmp
4+
DS*
5+
typings
6+
dist
7+
.vscode
8+
*.pid
9+
*.seed
10+
build/Release

README.md

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Angular Lib starter
2+
> Universal, AOT, Web Workers, ready lib starter. Use for your Angular libs
3+
4+
5+
## Getting started
6+
* fork this
7+
* clear the git history `git init .`
8+
* add your source code in `src`.
9+
* change the entry in `webpack.config.js`
10+
* change the output filnames in `package.json` to match your src files and webpack
11+
* `"main", "jsnext:main", "module", "types"`
12+
* build your project `yarn release` or `npm run release`
13+
14+
## Builds
15+
This starter prepares 2 different versions for builds of your lib
16+
* **esm** or ES2015 Modules
17+
* this build is a transpilation of your Typescript code to ES5 and ES2015 modules. Its' not bundled. This is needed for treeshaking when users use your lib
18+
* **UMD**
19+
* this is a bundle of ES5 code. What you would typically get from webpack or rollup.
20+
21+
The build system generates AOT metadata too, so you're good.
22+
23+
24+
## Scripts
25+
* `"test"`: runs the test in mocha on node
26+
* `"build:esm"`: builds the esm versions
27+
* `"build:bundle"`: builds the UMD version
28+
* `"build:aot"`: makes it work for aot
29+
* `"build"`: does all the above
30+
* `"copy"`: copies over file to dist
31+
* `"release"`: does all the above

custom.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
declare module '*'

mocha.opts

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
--webpack-config ./webpack.testing.js
2+
--require ./test-shim.js
3+
--ui bdd
4+
--glob *.spec.ts
5+
--recursive
6+
src

package.json

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
{
2+
"name": "angular-lib-starter",
3+
"version": "0.0.1",
4+
"description": "Starter to make Angular libs",
5+
"main": "bundle.js",
6+
"jsnext:main": "lib.module.js",
7+
"module": "lib.module.js",
8+
"types": "index.d.ts",
9+
"scripts": {
10+
"test": "rimraf ./tmp/mocha-webpack && mocha-webpack --opts 'mocha.opts'",
11+
"build:esm": "ntsc -p tsconfig.esm.json",
12+
"build:bundle": "webpack --progress --colors",
13+
"build:aot": "ngc",
14+
"build": "rimraf build && npm run build:esm && npm run build:bundle && npm run build:aot",
15+
"copy": "cp package.json dist && cp README.md dist",
16+
"release": "npm run build && npm run copy"
17+
},
18+
"license": "MIT",
19+
"devDependencies": {
20+
"@angular/common": "^4.1.3",
21+
"@angular/compiler": "^4.1.3",
22+
"@angular/compiler-cli": "^4.1.3",
23+
"@angular/core": "^4.1.3",
24+
"@angular/platform-browser": "^4.1.3",
25+
"@angular/platform-browser-dynamic": "^4.1.3",
26+
"@angular/platform-server": "^4.1.3",
27+
"@types/chai": "^3.5.2",
28+
"@types/mocha": "^2.2.41",
29+
"@types/node": "^7.0.18",
30+
"@types/sinon": "^2.2.2",
31+
"angular2-template-loader": "^0.6.2",
32+
"awesome-typescript-loader": "^3.1.3",
33+
"core-js": "^2.4.1",
34+
"jsdom": "^10.1.0",
35+
"mocha": "^3.4.1",
36+
"mocha-webpack": "^0.7.0",
37+
"ntypescript": "latest",
38+
"raw-loader": "^0.5.1",
39+
"rimraf": "^2.6.1",
40+
"rxjs": "^5.4.0",
41+
"source-map-support": "^0.4.15",
42+
"typescript": "^2.3.2",
43+
"webpack": "^2.5.1",
44+
"webpack-node-externals": "^1.6.0",
45+
"zone.js": "^0.8.10"
46+
},
47+
"dependencies": {
48+
"css-loader": "^0.28.1",
49+
"postcss-loader": "^2.0.5",
50+
"sass-loader": "^6.0.5",
51+
"to-string-loader": "^1.1.5"
52+
}
53+
}

src/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './lib.module'

src/lib.component.html

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<div class="lib">
2+
hello
3+
</div>

src/lib.component.ts

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { Component } from '@angular/core'
2+
3+
@Component({
4+
selector: 'lib',
5+
template: require('./lib.component.html')
6+
})
7+
export class LibComponent {}

src/lib.module.ts

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import {NgModule} from '@angular/core'
2+
import {CommonModule} from '@angular/common'
3+
import { LibComponent } from './lib.component'
4+
5+
6+
@NgModule({
7+
imports: [CommonModule],
8+
declarations: [LibComponent],
9+
exports: [LibComponent]
10+
})
11+
export class LibModule {}

src/lib.spec.ts

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
describe('test', () => {
2+
it('should be dope', () => {
3+
console.log('hello')
4+
})
5+
})

test-shim.js

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
require('source-map-support').install({
2+
environment: 'node'
3+
});
4+
5+
const jsdom = require('jsdom');
6+
7+
const {window} = new jsdom.JSDOM('<!doctype html><html><body></body></html>');
8+
9+
10+
// global.window = global.Window = window
11+
global.document = window.document;
12+
global.mediaMatch = window.mediaMatch;
13+
global.HTMLElement = window.HTMLElement;
14+
global.XMLHttpRequest = window.XMLHttpRequest;
15+
global.Node = window.Node;
16+
// global.scrollTo = window.scrollTo;
17+
// global.history = window.history;
18+
// global.clearInterval = window.clearInterval;
19+
// global.pageYOffset = window.pageYOffset;
20+
// global.sinon = require('sinon');
21+
22+
require('core-js/es6');
23+
require('core-js/es7/reflect');
24+
25+
require('zone.js/dist/zone');
26+
require('zone.js/dist/long-stack-trace-zone');
27+
require('zone.js/dist/proxy');
28+
require('zone.js/dist/sync-test');
29+
require('zone.js/dist/async-test');
30+
require('zone.js/dist/fake-async-test');
31+
32+
var testing = require('@angular/core/testing');
33+
var browser = require('@angular/platform-browser-dynamic/testing');
34+
35+
testing.TestBed.initTestEnvironment(browser.BrowserDynamicTestingModule, browser.platformBrowserDynamicTesting());

tsconfig.esm.json

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"compilerOptions": {
3+
"target": "es5",
4+
"module": "es2015",
5+
"sourceMap": true,
6+
"moduleResolution": "node",
7+
"emitDecoratorMetadata": true,
8+
"experimentalDecorators": true,
9+
"stripInternal": true,
10+
"declaration": true,
11+
"outDir": "./dist",
12+
"lib": ["es2015", "dom"]
13+
},
14+
"files": [
15+
"./src/index.ts"
16+
]
17+
}

tsconfig.json

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"angularCompilerOptions": {
3+
"skipTemplateCodegen": true
4+
},
5+
"compilerOptions": {
6+
"declaration": true,
7+
"emitDecoratorMetadata": true,
8+
"experimentalDecorators": true,
9+
"lib": [
10+
"es2015",
11+
"dom"
12+
],
13+
"module": "commonjs",
14+
"outDir": "./dist",
15+
"sourceMap": true,
16+
"stripInternal": true,
17+
"target": "es5",
18+
"typeRoots": [
19+
"./node_modules/@types",
20+
"./node_modules"
21+
],
22+
"types": [
23+
"node",
24+
"mocha",
25+
"chai"
26+
]
27+
},
28+
"files": [
29+
"./src/index.ts"
30+
]
31+
}

tslint.json

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
{
2+
"rulesDirectory": ["node_modules/tslint-no-unused-var"],
3+
"rules": {
4+
"max-line-length": [true, 100],
5+
"class-name": true,
6+
"comment-format": [
7+
true,
8+
"check-space"
9+
],
10+
"indent": [
11+
true,
12+
"spaces"
13+
],
14+
"eofline": true,
15+
"no-duplicate-variable": true,
16+
"no-eval": true,
17+
"no-arg": true,
18+
"no-internal-module": true,
19+
"no-trailing-whitespace": true,
20+
"no-bitwise": true,
21+
"no-shadowed-variable": true,
22+
"no-unused-expression": true,
23+
"no-unused-var": [true, {"ignore-pattern": "^(_.*)$"}],
24+
"one-line": [
25+
true,
26+
"check-catch",
27+
"check-else",
28+
"check-open-brace",
29+
"check-whitespace"
30+
],
31+
"quotemark": [
32+
true,
33+
"single",
34+
"avoid-escape"
35+
],
36+
// "semicolon": false,
37+
"typedef-whitespace": [
38+
true,
39+
{
40+
"call-signature": "nospace",
41+
"index-signature": "nospace",
42+
"parameter": "nospace",
43+
"property-declaration": "nospace",
44+
"variable-declaration": "nospace"
45+
}
46+
],
47+
"curly": true,
48+
"variable-name": [
49+
true,
50+
"ban-keywords",
51+
"check-format",
52+
"allow-leading-underscore"
53+
],
54+
"whitespace": [
55+
true,
56+
"check-branch",
57+
"check-decl",
58+
"check-operator",
59+
"check-separator",
60+
"check-type"
61+
]
62+
}
63+
}

webpack.config.js

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
const webpack = require('webpack')
2+
const path = require('path')
3+
const root = (_path) => {
4+
return path.resolve(__dirname, _path)
5+
}
6+
const moduleExternals = require('webpack-node-externals')
7+
8+
module.exports = (envOptions = {}) => {
9+
return ({
10+
entry: root('./src/index.ts'),
11+
output: {
12+
path: root('dist'),
13+
filename: 'bundle.js'
14+
},
15+
target: 'web',
16+
externals: [moduleExternals()],
17+
resolve: {
18+
extensions: ['.ts', '.js', '.html', '.scss', '.css'],
19+
},
20+
module: {
21+
rules: [
22+
{
23+
test: /\.ts$/,
24+
loaders: [
25+
{
26+
loader: 'awesome-typescript-loader',
27+
options: {
28+
declaration: false
29+
}
30+
},
31+
'angular2-template-loader'
32+
],
33+
exclude: [/node_modules/, /\.spec\.ts$/]
34+
},
35+
{
36+
test: /\.html$/,
37+
loader: 'raw-loader'
38+
},
39+
{
40+
test: /\.gql$/,
41+
loader: 'graphql-tag/loader'
42+
},
43+
{
44+
test: /\.scss$/,
45+
use: [
46+
'to-string-loader',
47+
'css-loader',
48+
'postcss-loader',
49+
'sass-loader'
50+
]
51+
}
52+
]
53+
},
54+
plugins: [
55+
new webpack.ContextReplacementPlugin(
56+
/angular(\\|\/)core(\\|\/)@angular/,
57+
root('src'), // location of your src
58+
{
59+
// your Angular Async Route paths relative to this root directory
60+
}
61+
)
62+
]
63+
})
64+
}

0 commit comments

Comments
 (0)