Skip to content

Commit

Permalink
Transpile and bundle (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
jfcere authored Aug 19, 2017
1 parent 207299d commit e483e9e
Show file tree
Hide file tree
Showing 9 changed files with 844 additions and 45 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@

# compiled output
/dist
/inline-template
/package
/tmp
*.ngfactory.ts
*.ngsummary.json
*.tar
*.tgz

# dependencies
/node_modules
Expand Down
2 changes: 2 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/*
!/dist
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ Here is the list of tasks that will be done on this library in a near future ...
- ~~Publish demo on github pages~~
- ~~Add CircleCI integration~~
- ~~Implement tests~~
- Transpile library to Javascript
- ~~Transpile library to Javascript~~

## Contribution

Expand Down
40 changes: 40 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
const CleanCSS = require('clean-css');
const gulp = require('gulp');
const htmlMinifier = require('html-minifier');
const inlineNg2Template = require('gulp-inline-ng2-template');
const sass = require('node-sass');

function sassProcessor(path, ext, file, callback) {
if (ext[0] === '.scss') {
const sassObj = sass.renderSync({ file: path });
if (sassObj && sassObj['css']) {
file = new CleanCSS({})
.minify(sassObj.css.toString('utf8'))
.styles;
}
}
return callback(null, file);
};

function minifyTemplate(path, ext, file, callback) {
const minifiedFile = htmlMinifier.minify(file, {
caseSensitive: true,
collapseInlineTagWhitespace: true,
collapseWhitespace: true,
removeComments: true,
});

callback(null, minifiedFile);
}

gulp.task('inline-template', function () {
return gulp.src(['./src/app/malihu-scrollbar/*.ts', '!./src/app/malihu-scrollbar/*.spec.ts'])
.pipe(inlineNg2Template({
base: '/src/app/malihu-scrollbar',
removeLineBreaks: true,
styleProcessor: sassProcessor,
templateProcessor: minifyTemplate,
useRelativePaths: true,
}))
.pipe(gulp.dest('./inline-template'));
});
39 changes: 30 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,29 @@
"custom",
"scrollbar"
],
"main": "./dist/lib/index.js",
"typings": "./dist/lib/index.d.ts",
"scripts": {
"build": "ng build",
"e2e": "ng e2e",
"lint": "tslint \"src/**/*.ts\"",
"ng": "ng",
"start": "ng serve",
"start": "npm run clean:dist && ng serve",
"test": "ng test",
"coveralls": "cat \"./coverage/lcov.info\" | \"./node_modules/coveralls/bin/coveralls.js\"",
"build:gh-pages": "ng build --prod --base-href \"https://jfcere.github.io/ngx-malihu-scrollbar/\"",
"publish:gh-pages": "angular-cli-ghpages --message \"Publish gh-pages\""
"publish:gh-pages": "angular-cli-ghpages --message \"Publish gh-pages\"",
"prebuild:lib": "npm run clean:dist && npm run clean:inline-template && npm run clean:artifact",
"build:lib": "npm run inline-template && npm run transpile && npm run package && npm run minify",
"postbuild:lib": "npm run clean:inline-template && npm run clean:artifact",
"clean:artifact": "rimraf src/**/*.ngfactory.ts src/**/*.ngsummary.json src/**/*.ngstyle.ts",
"clean:dist": "rimraf dist",
"clean:inline-template": "rimraf **/inline-template",
"clean:package": "rimraf package *.tar *.tgz",
"inline-template": "gulp inline-template",
"transpile": "ngc -p src/tsconfig.lib.json",
"package": "rollup -c",
"minify": "uglifyjs dist/bundles/ngx-malihu-scrollbar.umd.js --screw-ie8 --compress --mangle --comments --output dist/bundles/ngx-malihu-scrollbar.umd.min.js"
},
"private": false,
"dependencies": {
Expand All @@ -43,24 +56,26 @@
"malihu-custom-scrollbar-plugin": "^3.1.5"
},
"devDependencies": {
"@angular/cli": "1.0.0-rc.1",
"@angular/common": "^2.4.0",
"@angular/compiler": "^2.4.0",
"@angular/compiler-cli": "^2.4.0",
"@angular/core": "^2.4.0",
"@angular/forms": "^2.4.0",
"@angular/http": "^2.4.0",
"@angular/platform-browser": "^2.4.0",
"@angular/platform-browser-dynamic": "^2.4.0",
"@angular/router": "^3.4.0",
"core-js": "^2.4.1",
"coveralls": "^2.13.1",
"rxjs": "^5.1.0",
"zone.js": "^0.7.6",
"@angular/cli": "1.0.0-rc.1",
"@angular/compiler-cli": "^2.4.0",
"@types/jasmine": "2.5.38",
"@types/node": "~6.0.60",
"angular-cli-ghpages": "^0.5.0",
"clean-css": "^4.0.10",
"codelyzer": "~2.0.0",
"core-js": "^2.4.1",
"coveralls": "^2.13.1",
"gulp": "^3.9.1",
"gulp-inline-ng2-template": "^4.0.0",
"html-minifier": "^3.4.2",
"jasmine-core": "~2.5.2",
"jasmine-spec-reporter": "~3.2.0",
"karma": "~1.4.1",
Expand All @@ -70,10 +85,16 @@
"karma-jasmine": "~1.1.0",
"karma-jasmine-html-reporter": "^0.2.2",
"karma-junit-reporter": "^1.2.0",
"node-sass": "^4.5.3",
"protractor": "~5.1.0",
"rimraf": "^2.6.1",
"rollup": "^0.42.0",
"rxjs": "^5.1.0",
"ts-node": "~2.0.0",
"tslint": "~4.4.2",
"typescript": "^2.0.0"
"typescript": "^2.0.0",
"uglify-js": "^3.0.15",
"zone.js": "^0.7.6"
},
"peerDependencies": {
"@angular/core": "^2.4.0 || ^4.0.0",
Expand Down
17 changes: 17 additions & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
export default {
entry: 'dist/lib/malihu-scrollbar.module.js',
dest: 'dist/bundles/ngx-malihu-scrollbar.umd.js',
sourceMap: false,
format: 'umd',
moduleName: 'ng.malihuscrollbar',
globals: {
'@angular/core': 'ng.core',
'jquery': 'jquery',
'malihu-custom-scrollbar-plugin': 'malihu-custom-scrollbar-plugin',
},
external: [
'@angular/core',
'jquery',
'malihu-custom-scrollbar-plugin',
],
}
2 changes: 1 addition & 1 deletion src/app/malihu-scrollbar/malihu-scrollbar.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Injectable } from '@angular/core';

type ScrollElement = string | JQuery | HTMLElement;
export type ScrollElement = string | JQuery | HTMLElement;

@Injectable()
export class MalihuScrollbarService {
Expand Down
23 changes: 23 additions & 0 deletions src/tsconfig.lib.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"compilerOptions": {
"sourceMap": true,
"declaration": true,
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"lib": [
"es2016",
"dom"
],
"outDir": "../dist/lib",
"target": "es5",
"module": "es2015",
"baseUrl": "",
"typeRoots": [
"../node_modules/@types"
]
},
"include": [
"../inline-template/**/*"
]
}
Loading

0 comments on commit e483e9e

Please sign in to comment.