diff --git a/package.json b/package.json index 57cd166..8cb02d4 100644 --- a/package.json +++ b/package.json @@ -109,6 +109,7 @@ "strip-json-comments-cli": "1.0.1", "ts-jest": "20.0.6", "tslint": "5.4.3", + "tslint-config-prettier": "1.1.0", "tslint-config-standard": "6.0.1", "tslint-react": "3.0.0", "typedoc": "0.7.1", diff --git a/tslint.json b/tslint.json index 2468255..390336a 100644 --- a/tslint.json +++ b/tslint.json @@ -1,7 +1,8 @@ { "extends": [ "tslint-config-standard", - "tslint-react" + "tslint-react", + "tslint-config-prettier" ], "rules": { // tslint-react rules diff --git a/webpack.config.js b/webpack.config.js index 23f9423..9266f9b 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -1,18 +1,16 @@ -const { resolve } = require('path'); -const webpack = require('webpack'); -const UglifyJSPlugin = require('uglifyjs-webpack-plugin'); +const { resolve } = require('path') +const webpack = require('webpack') +const UglifyJSPlugin = require('uglifyjs-webpack-plugin') +const packageJSON = require('./package.json') +const packageName = normalizePackageName(packageJSON.name) -const packageJSON = require('./package.json'); -const packageName = normalizePackageName(packageJSON.name); - - -const LIB_NAME = pascalCase(packageName); +const LIB_NAME = pascalCase(packageName) const PATHS = { entryPoint: resolve(__dirname, 'src/index.ts'), umd: resolve(__dirname, 'umd'), - fesm: resolve(__dirname, 'lib-fesm') -}; + fesm: resolve(__dirname, 'lib-fesm'), +} const EXTERNALS = { // lodash: { @@ -21,7 +19,7 @@ const EXTERNALS = { // amd: "lodash", // root: "_" // } -}; +} const RULES = { ts: { @@ -36,9 +34,9 @@ const RULES = { // map already include everything for debugging // This cannot be set because -> Option 'declarationDir' cannot be specified without specifying option 'declaration'. // declaration: false, - } - } - ] + }, + }, + ], }, tsNext: { test: /\.tsx?$/, @@ -47,12 +45,12 @@ const RULES = { { loader: 'awesome-typescript-loader', options: { - target: 'es2017' - } - } - ] - } -}; + target: 'es2017', + }, + }, + ], + }, +} const PLUGINS = [ // enable scope hoisting @@ -60,13 +58,12 @@ const PLUGINS = [ // Apply minification only on the second bundle by using a RegEx on the name, which must end with `.min.js` new UglifyJSPlugin({ sourceMap: true, - include: /\.min\.js$/ + include: /\.min\.js$/, }), new webpack.LoaderOptionsPlugin({ - minimize: true - }) -]; - + minimize: true, + }), +] const config = env => { const UMDConfig = { @@ -76,7 +73,7 @@ const config = env => { // minification via UglifyJS entry: { [packageName]: [PATHS.entryPoint], - [`${packageName}.min`]: [PATHS.entryPoint] + [`${packageName}.min`]: [PATHS.entryPoint], }, // The output defines how and where we want the bundles. The special // value `[name]` in `filename` tell Webpack to use the name we defined above. @@ -89,12 +86,12 @@ const config = env => { library: LIB_NAME, // libraryExport: UMD.libName, // will name the AMD module of the UMD build. Otherwise an anonymous define is used. - umdNamedDefine: true + umdNamedDefine: true, }, // Add resolve for `tsx` and `ts` files, otherwise Webpack would // only look for common JavaScript file extension (.js) resolve: { - extensions: ['.ts', '.tsx', '.js'] + extensions: ['.ts', '.tsx', '.js'], }, // add here all 3rd party libraries that you will use as peerDependncies // https://webpack.js.org/guides/author-libraries/#add-externals @@ -104,14 +101,14 @@ const config = env => { devtool: 'source-map', plugins: PLUGINS, module: { - rules: [RULES.ts] - } - }; + rules: [RULES.ts], + }, + } const FESMconfig = Object.assign({}, UMDConfig, { - entry: { - 'index': [PATHS.entryPoint], - 'index.min': [PATHS.entryPoint] + entry: { + index: [PATHS.entryPoint], + 'index.min': [PATHS.entryPoint], }, output: { path: PATHS.fesm, @@ -120,33 +117,33 @@ const config = env => { module: { rules: [RULES.tsNext], }, - }); + }) - return [UMDConfig, FESMconfig]; -}; + return [UMDConfig, FESMconfig] +} -module.exports = config; +module.exports = config // helpers function camelCaseToDash(myStr) { - return myStr.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase(); + return myStr.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase() } function dashToCamelCase(myStr) { - return myStr.replace(/-([a-z])/g, g => g[1].toUpperCase()); + return myStr.replace(/-([a-z])/g, g => g[1].toUpperCase()) } function toUpperCase(myStr) { - return `${myStr.charAt(0).toUpperCase()}${myStr.substr(1)}`; + return `${myStr.charAt(0).toUpperCase()}${myStr.substr(1)}` } function pascalCase(myStr) { - return toUpperCase(dashToCamelCase(myStr)); + return toUpperCase(dashToCamelCase(myStr)) } function normalizePackageName(rawPackageName) { - const scopeEnd = rawPackageName.indexOf('/') + 1; + const scopeEnd = rawPackageName.indexOf('/') + 1 - return rawPackageName.substring(scopeEnd); + return rawPackageName.substring(scopeEnd) } diff --git a/yarn.lock b/yarn.lock index 1a71694..793d91f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4466,6 +4466,10 @@ tslib@^1.0.0, tslib@^1.7.1: version "1.7.1" resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.7.1.tgz#bc8004164691923a79fe8378bbeb3da2017538ec" +tslint-config-prettier@1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/tslint-config-prettier/-/tslint-config-prettier-1.1.0.tgz#40c026a56e4da27063b3e9bcd71f4f8109fee369" + tslint-config-standard@6.0.1: version "6.0.1" resolved "https://registry.yarnpkg.com/tslint-config-standard/-/tslint-config-standard-6.0.1.tgz#a04ba0a794759e877287056f549b081e47a56d6c"