Skip to content

Extend css task #561

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion gulpfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ gulp.task('build.dev', done =>
runSequence('clean.dev',
'tslint',
'build.assets.dev',
'build.html_css',
'build.js.dev',
'build.index.dev',
done));
Expand Down Expand Up @@ -44,7 +45,8 @@ gulp.task('build.prod', done =>
runSequence('clean.prod',
'tslint',
'build.assets.prod',
'build.html_css.prod',
'build.html_css',
'copy.js.prod',
'build.js.prod',
'build.bundles',
'build.bundles.app',
Expand Down
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,26 @@
"license": "MIT",
"devDependencies": {
"async": "^1.4.2",
"autoprefixer": "^6.3.3",
"browser-sync": "^2.11.1",
"chalk": "^1.1.1",
"connect": "^3.4.1",
"connect-history-api-fallback": "^1.1.0",
"connect-livereload": "^0.5.3",
"cssnano": "^3.5.2",
"del": "^2.2.0",
"event-stream": "^3.3.2",
"express": "~4.13.1",
"extend": "^3.0.0",
"gulp": "^3.9.0",
"gulp-cached": "^1.1.0",
"gulp-concat": "^2.5.2",
"gulp-cssnano": "^2.0.0",
"gulp-filter": "^2.0.2",
"gulp-inject": "^1.3.1",
"gulp-inline-ng2-template": "^1.1.0",
"gulp-load-plugins": "^0.10.0",
"gulp-plumber": "~1.0.1",
"gulp-postcss": "^6.1.0",
"gulp-shell": "~0.4.3",
"gulp-sourcemaps": "~1.6.0",
"gulp-template": "^3.0.0",
Expand All @@ -74,6 +77,7 @@
"ng2lint": "0.0.9",
"open": "0.0.5",
"phantomjs-prebuilt": "^2.1.4",
"postcss-assets": "^4.0.1",
"protractor": "^3.0.0",
"remap-istanbul": "^0.5.1",
"rimraf": "^2.5.2",
Expand Down
2 changes: 1 addition & 1 deletion src/app/components/toolbar.component.css
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ h1 {
}

more {
background: url("./assets/svg/more.svg");
background: resolve("more.svg");
float: right;
height: 24px;
margin-top: 12px;
Expand Down
14 changes: 14 additions & 0 deletions tools/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,20 @@ export const SYSTEM_BUILDER_CONFIG = {
}
};

// ----------------
// Autoprefixer configuration.
export const BROWSER_LIST = [
'ie >= 10',
'ie_mob >= 10',
'ff >= 30',
'chrome >= 34',
'safari >= 7',
'opera >= 23',
'ios >= 7',
'android >= 4.4',
'bb >= 10'
];

// --------------
// Private.

Expand Down
8 changes: 8 additions & 0 deletions tools/manual_typings/autoprefixer.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
declare module 'autoprefixer' {
interface Options {
browsers?: string | string[]
}
function autoprefixer(options: Options): NodeJS.ReadWriteStream;
module autoprefixer {}
export = autoprefixer;
}
8 changes: 8 additions & 0 deletions tools/manual_typings/cssnano.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
declare module 'cssnano' {
interface Options {
discardComments?: Object
}
function cssnano(options: Options): NodeJS.ReadWriteStream;
module cssnano {}
export = cssnano;
}
12 changes: 12 additions & 0 deletions tools/manual_typings/postcss-assets.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
declare module 'postcss-assets' {
interface Options {
relative?: boolean,
cachebuster?: boolean | Function,
basePath?: string,
baseUrl?: string,
loadPaths: string[]
}
function postCSSAssets(options: Options): NodeJS.ReadWriteStream;
module postCSSAssets {}
export = postCSSAssets;
}
41 changes: 0 additions & 41 deletions tools/tasks/build.html_css.prod.ts

This file was deleted.

69 changes: 69 additions & 0 deletions tools/tasks/build.html_css.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import * as merge from 'merge-stream';
import * as autoprefixer from 'autoprefixer';
import * as assets from 'postcss-assets';
import * as cssnano from 'cssnano';
import {join} from 'path';
import {
APP_SRC,
TMP_DIR,
APP_ASSETS,
CSS_PROD_BUNDLE,
CSS_DEST,
APP_DEST,
BROWSER_LIST,
ENV
} from '../config';

const processors = [
autoprefixer({
browsers: BROWSER_LIST
}),
assets({
basePath: APP_DEST,
loadPaths: [join('assets', '**', '*')]
})
];

const isProd = ENV === 'prod';

if (isProd) {
processors.push(
cssnano({
discardComments: {removeAll: true}
})
);
}

export = function buildHTMLCSS(gulp, plugins) {
return function () {

return merge(processComponentCss(), prepareTemplates(), processExternalCss());

function prepareTemplates() {
return gulp.src(join(APP_SRC, '**', '*.html'))
.pipe(gulp.dest(TMP_DIR));
}

function processComponentCss() {
return gulp.src([
join(APP_SRC, '**', '*.css'),
'!' + join(APP_SRC, 'assets', '**', '*.css')
])
.pipe(isProd ? plugins.cached('process-component-css') : plugins.util.noop())
.pipe(plugins.postcss(processors))
.pipe(gulp.dest(isProd ? TMP_DIR: APP_DEST));
}

function processExternalCss() {
return gulp.src(getExternalCss().map(r => r.src))
.pipe(isProd ? plugins.cached('process-external-css') : plugins.util.noop())
.pipe(plugins.postcss(processors))
.pipe(isProd ? plugins.concat(CSS_PROD_BUNDLE) : plugins.util.noop())
.pipe(gulp.dest(CSS_DEST));
}

function getExternalCss() {
return APP_ASSETS.filter(d => /\.css$/.test(d.src));
}
};
};
6 changes: 2 additions & 4 deletions tools/tasks/build.js.prod.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {join} from 'path';
import {APP_SRC, TMP_DIR} from '../config';
import {TMP_DIR} from '../config';
import {templateLocals, tsProjectFn} from '../utils';

const INLINE_OPTIONS = {
Expand All @@ -14,9 +14,7 @@ export = function buildJSProd(gulp, plugins) {
let src = [
'typings/browser.d.ts',
'tools/manual_typings/**/*.d.ts',
join(APP_SRC, '**/*.ts'),
'!' + join(APP_SRC, '**/*.spec.ts'),
'!' + join(APP_SRC, '**/*.e2e.ts')
join(TMP_DIR, '**/*.ts')
];
let result = gulp.src(src)
.pipe(plugins.plumber())
Expand Down
18 changes: 18 additions & 0 deletions tools/tasks/copy.js.prod.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import {join} from 'path';
import {
APP_SRC,
TMP_DIR
} from '../config';

export = function copyJSProd(gulp, plugins) {
return function () {

let src = [
join(APP_SRC, '**/*.ts'),
'!' + join(APP_SRC, '**/*.spec.ts'),
'!' + join(APP_SRC, '**/*.e2e.ts')
];
return gulp.src(src)
.pipe(gulp.dest(TMP_DIR));
};
};