2017-04-23 9 views
0

おはよう; 私はangular-cliで角度4を使用しています。私はどのようにprod環境で自分のコンポーネントの.d.tsファイルを生成するのだろうかと思います。prodフォルダにwebpackとangular-cliを含む.d.tsファイルを生成する

は角2では、私はこの https://medium.com/@OCombe/how-to-publish-a-library-for-angular-2-on-npm-5f48cdabf435

パッケージJSONファイル

{ 
    "name": "zippy", 
    "version": "1.0.0", 
    "license": "MIT", 
    "main": "zippy.bundle.js", 
    "jsnext:main": "zippy.module.js", 
    "module": "zippy.module.js", 
    "types": "zippy.module.d.ts", 

    "scripts": { 
    "ng": "ng", 
    "start": "ng serve", 
    "build": "ng build", 
    "test": "ng test", 
    "lint": "ng lint", 
    "e2e": "ng e2e" 
    }, 
    "private": true, 
    "dependencies": { 
    "@angular/common": "^4.0.0", 
    "@angular/compiler": "^4.0.0", 
    "@angular/core": "^4.0.0", 
    "@angular/forms": "^4.0.0", 
    "@angular/http": "^4.0.0", 
    "@angular/platform-browser": "^4.0.0", 
    "@angular/platform-browser-dynamic": "^4.0.0", 
    "@angular/router": "^4.0.0", 
    "core-js": "^2.4.1", 
    "rxjs": "^5.1.0", 
    "zone.js": "^0.8.4" 
    }, 
    "devDependencies": { 
    "@angular/cli": "1.0.0", 
    "@angular/compiler-cli": "^4.0.0", 
    "@types/jasmine": "2.5.38", 
    "@types/node": "~6.0.60", 
    "codelyzer": "~2.0.0", 
    "jasmine-core": "~2.5.2", 
    "jasmine-spec-reporter": "~3.2.0", 
    "karma": "~1.4.1", 
    "karma-chrome-launcher": "~2.0.0", 
    "karma-cli": "~1.0.1", 
    "karma-jasmine": "~1.1.0", 
    "karma-jasmine-html-reporter": "^0.2.2", 
    "karma-coverage-istanbul-reporter": "^0.2.0", 
    "protractor": "~5.1.0", 
    "ts-node": "~2.0.0", 
    "tslint": "~4.5.0", 
    "typescript": "~2.2.0" 
    }, 
    "angularCompilerOptions": { 
    "skipTemplateCodegen": true 
    } 
} 

のTSconfigファイル

{ 
    "compileOnSave": false, 
    "compilerOptions": { 
    "outDir": "./dist", 
    "baseUrl": "src", 
    "sourceMap": true,  
    "moduleResolution": "node", 
    "emitDecoratorMetadata": true, 
    "experimentalDecorators": true, 
    "target": "es5", 
    "typeRoots": [ 
     "node_modules/@types" 
    ], 
    "lib": [ 
     "es2016", 
     "dom" 
    ], 
    "declaration": true, 
    "files": [ 
     "./src/app/zippy.moodule.ts" 
     ] 
    } 
} 

を達成するために、このチュートリアルを使用して、私は真心を込めNGビルド--prodコマンド を実行します

WebPACKの設定ファイル

あなたはそれがJS corspondingファイルのd.tsファイルを生成できるようにTSconfigのファイルにフラグを--declaration渡す必要が
const path = require('path'); 
const ProgressPlugin = require('webpack/lib/ProgressPlugin'); 
const HtmlWebpackPlugin = require('html-webpack-plugin'); 
const ExtractTextPlugin = require('extract-text-webpack-plugin'); 
const autoprefixer = require('autoprefixer'); 
const postcssUrl = require('postcss-url'); 

const { NoEmitOnErrorsPlugin, LoaderOptionsPlugin } = require('webpack'); 
const { GlobCopyWebpackPlugin, BaseHrefWebpackPlugin } = require('@angular/cli/plugins/webpack'); 
const { CommonsChunkPlugin } = require('webpack').optimize; 
const { AotPlugin } = require('@ngtools/webpack'); 

const nodeModules = path.join(process.cwd(), 'node_modules'); 
const entryPoints = ["inline","polyfills","sw-register","styles","vendor","main"]; 
const baseHref = ""; 
const deployUrl = ""; 




module.exports = { 
    "devtool": "source-map", 
    "resolve": { 
    "extensions": [ 
     ".ts", 
     ".js" 
    ], 
    "modules": [ 
     "./node_modules" 
    ] 
    }, 
    "resolveLoader": { 
    "modules": [ 
     "./node_modules" 
    ] 
    }, 
    "entry": { 
    "main": [ 
     "./src/main.ts" 
    ], 
    "polyfills": [ 
     "./src/polyfills.ts" 
    ], 
    "styles": [ 
     "./src/styles.css" 
    ] 
    }, 
    "output": { 
    "path": path.join(process.cwd(), "dist"), 
    "filename": "[name].bundle.js", 
    "chunkFilename": "[id].chunk.js" 
    }, 
    "module": { 
    "rules": [ 
     { 
     "enforce": "pre", 
     "test": /\.js$/, 
     "loader": "source-map-loader", 
     "exclude": [ 
      /\/node_modules\// 
     ] 
     }, 
     { 
     "test": /\.json$/, 
     "loader": "json-loader" 
     }, 
     { 
     "test": /\.html$/, 
     "loader": "raw-loader" 
     }, 
     { 
     "test": /\.(eot|svg)$/, 
     "loader": "file-loader?name=[name].[hash:20].[ext]" 
     }, 
     { 
     "test": /\.(jpg|png|gif|otf|ttf|woff|woff2|cur|ani)$/, 
     "loader": "url-loader?name=[name].[hash:20].[ext]&limit=10000" 
     }, 
     { 
     "exclude": [ 
      path.join(process.cwd(), "src/styles.css") 
     ], 
     "test": /\.css$/, 
     "loaders": [ 
      "exports-loader?module.exports.toString()", 
      "css-loader?{\"sourceMap\":false,\"importLoaders\":1}", 
      "postcss-loader" 
     ] 
     }, 
     { 
     "exclude": [ 
      path.join(process.cwd(), "src/styles.css") 
     ], 
     "test": /\.scss$|\.sass$/, 
     "loaders": [ 
      "exports-loader?module.exports.toString()", 
      "css-loader?{\"sourceMap\":false,\"importLoaders\":1}", 
      "postcss-loader", 
      "sass-loader" 
     ] 
     }, 
     { 
     "exclude": [ 
      path.join(process.cwd(), "src/styles.css") 
     ], 
     "test": /\.less$/, 
     "loaders": [ 
      "exports-loader?module.exports.toString()", 
      "css-loader?{\"sourceMap\":false,\"importLoaders\":1}", 
      "postcss-loader", 
      "less-loader" 
     ] 
     }, 
     { 
     "exclude": [ 
      path.join(process.cwd(), "src/styles.css") 
     ], 
     "test": /\.styl$/, 
     "loaders": [ 
      "exports-loader?module.exports.toString()", 
      "css-loader?{\"sourceMap\":false,\"importLoaders\":1}", 
      "postcss-loader", 
      "stylus-loader?{\"sourceMap\":false,\"paths\":[]}" 
     ] 
     }, 
     { 
     "include": [ 
      path.join(process.cwd(), "src/styles.css") 
     ], 
     "test": /\.css$/, 
     "loaders": ExtractTextPlugin.extract({ 
    "use": [ 
    "css-loader?{\"sourceMap\":false,\"importLoaders\":1}", 
    "postcss-loader" 
    ], 
    "fallback": "style-loader", 
    "publicPath": "" 
}) 
     }, 
     { 
     "include": [ 
      path.join(process.cwd(), "src/styles.css") 
     ], 
     "test": /\.scss$|\.sass$/, 
     "loaders": ExtractTextPlugin.extract({ 
    "use": [ 
    "css-loader?{\"sourceMap\":false,\"importLoaders\":1}", 
    "postcss-loader", 
    "sass-loader" 
    ], 
    "fallback": "style-loader", 
    "publicPath": "" 
}) 
     }, 
     { 
     "include": [ 
      path.join(process.cwd(), "src/styles.css") 
     ], 
     "test": /\.less$/, 
     "loaders": ExtractTextPlugin.extract({ 
    "use": [ 
    "css-loader?{\"sourceMap\":false,\"importLoaders\":1}", 
    "postcss-loader", 
    "less-loader" 
    ], 
    "fallback": "style-loader", 
    "publicPath": "" 
}) 
     }, 
     { 
     "include": [ 
      path.join(process.cwd(), "src/styles.css") 
     ], 
     "test": /\.styl$/, 
     "loaders": ExtractTextPlugin.extract({ 
    "use": [ 
    "css-loader?{\"sourceMap\":false,\"importLoaders\":1}", 
    "postcss-loader", 
    "stylus-loader?{\"sourceMap\":false,\"paths\":[]}" 
    ], 
    "fallback": "style-loader", 
    "publicPath": "" 
}) 
     }, 
     { 
     "test": /\.ts$/, 
     "loader": "@ngtools/webpack" 
     } 
    ] 
    }, 
    "plugins": [ 
    new NoEmitOnErrorsPlugin(), 
    new GlobCopyWebpackPlugin({ 
     "patterns": [ 
     "assets", 
     "favicon.ico" 
     ], 
     "globOptions": { 
     "cwd": "/home/riadh/WebstormProjects/zipdemo/src", 
     "dot": true, 
     "ignore": "**/.gitkeep" 
     } 
    }), 
    new ProgressPlugin(), 
    new HtmlWebpackPlugin({ 
     "template": "./src/index.html", 
     "filename": "./index.html", 
     "hash": false, 
     "inject": true, 
     "compile": true, 
     "favicon": false, 
     "minify": false, 
     "cache": true, 
     "showErrors": true, 
     "chunks": "all", 
     "excludeChunks": [], 
     "title": "Webpack App", 
     "xhtml": true, 
     "chunksSortMode": function sort(left, right) { 
     let leftIndex = entryPoints.indexOf(left.names[0]); 
     let rightindex = entryPoints.indexOf(right.names[0]); 
     if (leftIndex > rightindex) { 
      return 1; 
     } 
     else if (leftIndex < rightindex) { 
      return -1; 
     } 
     else { 
      return 0; 
     } 
    } 
    }), 
    new BaseHrefWebpackPlugin({}), 
    new CommonsChunkPlugin({ 
     "name": "inline", 
     "minChunks": null 
    }), 
    new CommonsChunkPlugin({ 
     "name": "vendor", 
     "minChunks": (module) => module.resource && module.resource.startsWith(nodeModules), 
     "chunks": [ 
     "main" 
     ] 
    }), 
    new ExtractTextPlugin({ 
     "filename": "[name].bundle.css", 
     "disable": true 
    }), 
    new LoaderOptionsPlugin({ 
     "sourceMap": false, 
     "options": { 
     "postcss": [ 
      autoprefixer(), 
      postcssUrl({"url": (URL) => { 
      // Only convert root relative URLs, which CSS-Loader won't process into require(). 
      if (!URL.startsWith('/') || URL.startsWith('//')) { 
       return URL; 
      } 
      if (deployUrl.match(/:\/\//)) { 
       // If deployUrl contains a scheme, ignore baseHref use deployUrl as is. 
       return `${deployUrl.replace(/\/$/, '')}${URL}`; 
      } 
      else if (baseHref.match(/:\/\//)) { 
       // If baseHref contains a scheme, include it as is. 
       return baseHref.replace(/\/$/, '') + 
        `/${deployUrl}/${URL}`.replace(/\/\/+/g, '/'); 
      } 
      else { 
       // Join together base-href, deploy-url and the original URL. 
       // Also dedupe multiple slashes into single ones. 
       return `/${baseHref}/${deployUrl}/${URL}`.replace(/\/\/+/g, '/'); 
      } 
     }}) 
     ], 
     "sassLoader": { 
      "sourceMap": false, 
      "includePaths": [] 
     }, 
     "lessLoader": { 
      "sourceMap": false 
     }, 
     "context": "" 
     } 
    }), 
    new AotPlugin({ 
     "mainPath": "main.ts", 
     "hostReplacementPaths": { 
     "environments/environment.ts": "environments/environment.ts" 
     }, 
     "exclude": [], 
     "tsConfigPath": "src/tsconfig.app.json", 
     "skipCodeGeneration": true 
    }) 
    ], 
    "node": { 
    "fs": "empty", 
    "global": true, 
    "crypto": "empty", 
    "tls": "empty", 
    "net": "empty", 
    "process": true, 
    "module": false, 
    "clearImmediate": false, 
    "setImmediate": false 
    } 
}; 

答えて

0
+0

は私が推測する@AdouaniRiadh更新プラザ:) –

+1

を見ますWebpack内でts-loaderまたはawesome-typescript-loaderを使用しており、d.tsファイルが生成されないことがあります。もしあなたがangular/compiler-cliを使っていれば、それらのファイルを生成するか、またはtscをコンパイラのファイルに実行するだけですが、jsファイルのような他のファイルは必要ありません。私はtscを使用してコンパイルするために2つのスクリプトを作成し、すべての.jsファイルをクリーンアップすることをお勧めします –

+0

webpack設定ファイルを配置しました。 –

関連する問題