diff --git a/CUSTOMIZE-cn.md b/CUSTOMIZE-cn.md new file mode 100644 index 000000000000..61db93825544 --- /dev/null +++ b/CUSTOMIZE-cn.md @@ -0,0 +1,10 @@ +# 如何定制自己的angular cli + +1. fork官方库,并clone到本地 +1. 修改源码,主要的文件都在`packages/@angular/cli`下,其中webpack配置位于`packages/@angular/cli/models`下 +1. 修改`packages/@angular/cli/blueprints/ng/files/package.json`的`devDependencies/"@angular/cli"`,指向你准备发布到的仓库,如`git+https://github.com/asnowwolf/ng-cli-2.git#v<%= version %>` +1. 运行`npm run build`命令,构建出自己的版本。 +1. 把`dist/@angular/cli`目录上传到某个独立的git仓库,如`https://github.com/asnowwolf/ng-cli-2`:初始化、添加、提交、打上tag,并使用`git push --tags`推送上去。 +1. 在开发者电脑上运行`npm i -g https://github.com/asnowwolf/ng-cli-2.git\#v1.1.1`(把url部分替换成你自己的发布位置) + +这样你本地的cli就是定制版了。 \ No newline at end of file diff --git a/package.json b/package.json index 683fb9067206..54bf47afe867 100644 --- a/package.json +++ b/package.json @@ -73,6 +73,8 @@ "loader-utils": "^1.0.2", "lodash": "^4.11.1", "magic-string": "^0.22.3", + "markdown-loader": "^2.0.0", + "markup-inline-loader": "^0.2.0", "memory-fs": "^0.4.1", "minimatch": "^3.0.3", "node-modules-path": "^1.0.0", diff --git a/packages/@angular/cli/blueprints/component/files/__path__/__name__.component.__styleext__ b/packages/@angular/cli/blueprints/component/files/__path__/__name__.component.__styleext__ index e69de29bb2d1..5d4e87f30f63 100644 --- a/packages/@angular/cli/blueprints/component/files/__path__/__name__.component.__styleext__ +++ b/packages/@angular/cli/blueprints/component/files/__path__/__name__.component.__styleext__ @@ -0,0 +1,3 @@ +:host { + display: block; +} diff --git a/packages/@angular/cli/blueprints/component/files/__path__/__name__.component.ts b/packages/@angular/cli/blueprints/component/files/__path__/__name__.component.ts index 2b23a2899848..57db413477ee 100644 --- a/packages/@angular/cli/blueprints/component/files/__path__/__name__.component.ts +++ b/packages/@angular/cli/blueprints/component/files/__path__/__name__.component.ts @@ -17,7 +17,7 @@ export class <%= classifiedModuleName %>Component implements OnInit { constructor() { } - ngOnInit() { + ngOnInit(): void { } } diff --git a/packages/@angular/cli/blueprints/ng/files/__path__/app/app.component.__styleext__ b/packages/@angular/cli/blueprints/ng/files/__path__/app/app.component.__styleext__ index e69de29bb2d1..5d4e87f30f63 100644 --- a/packages/@angular/cli/blueprints/ng/files/__path__/app/app.component.__styleext__ +++ b/packages/@angular/cli/blueprints/ng/files/__path__/app/app.component.__styleext__ @@ -0,0 +1,3 @@ +:host { + display: block; +} diff --git a/packages/@angular/cli/blueprints/ng/files/package.json b/packages/@angular/cli/blueprints/ng/files/package.json index 1808271d071e..1d60402f70e3 100644 --- a/packages/@angular/cli/blueprints/ng/files/package.json +++ b/packages/@angular/cli/blueprints/ng/files/package.json @@ -4,10 +4,11 @@ "license": "MIT", "scripts": { "ng": "ng", - "start": "ng serve", - "build": "ng build",<% if (!minimal){ %> + "start": "ng serve --extract-css --proxy-config=./proxy.conf.js -p 0", + "build": "ng build --extract-css -prod",<% if (!minimal){ %> "test": "ng test", - "lint": "ng lint", + "lint": "ng lint \"src/**/*.ts\"", + "ci": "npm run lint && ng test --single-run", "e2e": "ng e2e"<% } else { %> "test": "echo \"Error: no test... minimal project\" && exit 1", "lint": "echo \"Error: no lint... minimal project\" && exit 1", @@ -29,7 +30,7 @@ "zone.js": "^0.8.14" }, "devDependencies": { - "@angular/cli": "<%= version %>", + "@angular/cli": "git+https://github.com/asnowwolf/ng-cli-2.git#v<%= version %>", "@angular/compiler-cli": "^4.2.4", "@angular/language-service": "^4.2.4",<% if (!minimal) { %> "@types/jasmine": "~2.5.53", diff --git a/packages/@angular/cli/blueprints/ng/files/proxy.conf.js b/packages/@angular/cli/blueprints/ng/files/proxy.conf.js new file mode 100644 index 000000000000..2d1b94a77f1d --- /dev/null +++ b/packages/@angular/cli/blueprints/ng/files/proxy.conf.js @@ -0,0 +1,6 @@ +module.exports = { + '/api/': { + target: 'http://localhost:8080/', + pathRewrite: {'^/api': ''} + } +}; diff --git a/packages/@angular/cli/models/webpack-configs/common.ts b/packages/@angular/cli/models/webpack-configs/common.ts index 7aed537e008d..0f4d6fee07fa 100644 --- a/packages/@angular/cli/models/webpack-configs/common.ts +++ b/packages/@angular/cli/models/webpack-configs/common.ts @@ -16,6 +16,10 @@ const CircularDependencyPlugin = require('circular-dependency-plugin'); * require('source-map-loader') * require('raw-loader') * require('script-loader') + * require('html-loader') + * require('markup-inline-loader') + * require('markdown-loader') + * require('json-loader') * require('url-loader') * require('file-loader') * require('@angular-devkit/build-optimizer') @@ -105,11 +109,12 @@ export function getCommonConfig(wco: WebpackConfigOptions) { module: { rules: [ { enforce: 'pre', test: /\.js$/, loader: 'source-map-loader', exclude: [nodeModules] }, - { test: /\.html$/, loader: 'raw-loader' }, - { test: /\.(eot|svg|cur)$/, loader: `file-loader?name=[name]${hashFormat.file}.[ext]` }, + { test: /\.html$/, loaders: ['html-loader', 'markup-inline-loader'] }, + { test: /\.md$/, loaders: ['html-loader', 'markup-inline-loader', 'markdown-loader'] }, + { test: /\.(eot|svg|cur)$/, loader: `url-loader?name=images/[name]${hashFormat.file}.[ext]&limit=256` }, { test: /\.(jpg|png|webp|gif|otf|ttf|woff|woff2|ani)$/, - loader: `url-loader?name=[name]${hashFormat.file}.[ext]&limit=10000` + loader: `url-loader?name=images/[name]${hashFormat.file}.[ext]&limit=1024` } ].concat(extraRules) }, diff --git a/packages/@angular/cli/models/webpack-configs/styles.ts b/packages/@angular/cli/models/webpack-configs/styles.ts index bb968e435aee..1da9e5ba64ab 100644 --- a/packages/@angular/cli/models/webpack-configs/styles.ts +++ b/packages/@angular/cli/models/webpack-configs/styles.ts @@ -38,7 +38,7 @@ export function getStylesConfig(wco: WebpackConfigOptions) { // style-loader does not support sourcemaps without absolute publicPath, so it's // better to disable them when not extracting css // https://github.com/webpack-contrib/style-loader#recommended-configuration - const cssSourceMap = buildOptions.extractCss && buildOptions.sourcemaps; + const cssSourceMap = buildOptions.sourcemaps; // Minify/optimize css in production. const minimizeCss = buildOptions.target === 'production'; diff --git a/packages/@angular/cli/models/webpack-configs/typescript.ts b/packages/@angular/cli/models/webpack-configs/typescript.ts index 39c7a7295687..fab7237c5fee 100644 --- a/packages/@angular/cli/models/webpack-configs/typescript.ts +++ b/packages/@angular/cli/models/webpack-configs/typescript.ts @@ -71,7 +71,7 @@ function _createAotPlugin(wco: WebpackConfigOptions, options: any) { replaceExport: appConfig.platform === 'server', hostReplacementPaths, // If we don't explicitely list excludes, it will default to `['**/*.spec.ts']`. - exclude: [] + exclude: [], }, options)); } diff --git a/packages/@angular/cli/models/webpack-configs/utils.ts b/packages/@angular/cli/models/webpack-configs/utils.ts index e44e4d34b00b..3a3ca6c2fe76 100644 --- a/packages/@angular/cli/models/webpack-configs/utils.ts +++ b/packages/@angular/cli/models/webpack-configs/utils.ts @@ -78,9 +78,9 @@ export interface HashFormat { export function getOutputHashFormat(option: string, length = 20): HashFormat { /* tslint:disable:max-line-length */ const hashFormats: { [option: string]: HashFormat } = { - none: { chunk: '', extract: '', file: '' }, + none: { chunk: '', extract: '', file: `.[hash:${length}]` }, media: { chunk: '', extract: '', file: `.[hash:${length}]` }, - bundles: { chunk: `.[chunkhash:${length}]`, extract: `.[contenthash:${length}]`, file: '' }, + bundles: { chunk: `.[chunkhash:${length}]`, extract: `.[contenthash:${length}]`, file: `.[hash:${length}]` }, all: { chunk: `.[chunkhash:${length}]`, extract: `.[contenthash:${length}]`, file: `.[hash:${length}]` }, }; /* tslint:enable:max-line-length */ diff --git a/packages/@angular/cli/package.json b/packages/@angular/cli/package.json index 1dcdd542bd79..d26011d737ff 100644 --- a/packages/@angular/cli/package.json +++ b/packages/@angular/cli/package.json @@ -36,6 +36,7 @@ "common-tags": "^1.3.1", "core-object": "^3.1.0", "css-loader": "^0.28.1", + "css-with-mapping-loader": "0.0.5", "cssnano": "^3.10.0", "denodeify": "^1.2.1", "diff": "^3.1.0", @@ -49,6 +50,7 @@ "glob": "^7.0.3", "heimdalljs": "^0.2.4", "heimdalljs-logger": "^0.1.9", + "html-loader": "^0.4.4", "html-webpack-plugin": "^2.29.0", "inflection": "^1.7.0", "inquirer": "^3.0.0", @@ -58,6 +60,7 @@ "less-loader": "^4.0.5", "license-webpack-plugin": "^0.5.1", "lodash": "^4.11.1", + "markup-inline-loader": "^0.1.3", "memory-fs": "^0.4.1", "minimatch": "^3.0.3", "node-modules-path": "^1.0.0",