<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Vladimir Tolstikov on Medium]]></title>
        <description><![CDATA[Stories by Vladimir Tolstikov on Medium]]></description>
        <link>https://medium.com/@vladimirtolstikov?source=rss-ca6ca0d4d6e6------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*01LpSL_NF5-8C54G0zfydg.jpeg</url>
            <title>Stories by Vladimir Tolstikov on Medium</title>
            <link>https://medium.com/@vladimirtolstikov?source=rss-ca6ca0d4d6e6------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 13:34:52 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@vladimirtolstikov/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Safari bugs: CSS variables not applied immediately if used in animation]]></title>
            <link>https://medium.com/@vladimirtolstikov/safari-bugs-css-variables-not-applied-immediately-if-used-in-animation-ded7e0ce9163?source=rss-ca6ca0d4d6e6------2</link>
            <guid isPermaLink="false">https://medium.com/p/ded7e0ce9163</guid>
            <category><![CDATA[safari-browser]]></category>
            <category><![CDATA[css]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[html]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Vladimir Tolstikov]]></dc:creator>
            <pubDate>Wed, 05 Oct 2022 18:53:28 GMT</pubDate>
            <atom:updated>2022-10-05T18:53:28.644Z</atom:updated>
            <content:encoded><![CDATA[<p>I’m opening new article category named “Safari bugs” :)</p><p>I think many of you, who deep into Frontend, knows that “Safari as a new IE” and we should deal with it these days on the daily basis. Mostly things go smoothly, but if you start to do something fancy or want things to work slick, especially around animations, you start to see that all is working ok in Chrome but have issues in Safari and you start googling and trying different approaches and hacks.</p><p>New issues with Safari discovered today when I was trying to build <strong>cool animated photo gallery</strong> for <a href="http://bobrosoft.com/">my re-designed personal webpage</a>.</p><h4>Bugs are next:</h4><blockquote>1. CSS variables not applied immediately if used in animation @ keyframes</blockquote><blockquote>2. When animating image, it may appear empty if you’re changing src URL too quickly (maybe happens even without animation)</blockquote><p>So to deal with it, it required to place some fancy delay hacks (fortunately that helped)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_Dz9ipoG5DTipNkQ8oiEAQ.png" /><figcaption>(need to use window.setTimeout because of wrong TypeScript type-hinting in IDE)</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oIvVgqTxBd6H23xbUTgKpQ.png" /><figcaption>(hacks usage in layout)</figcaption></figure><p>In Safari’s defence I can say that its rendering works smoother and with higher FPS (especially noticeable when scrolling in Chrome and in Safari) <a href="http://bobrosoft.com/">in that my current project</a>, but those bugs… eh…</p><h4>Bonus lifehack</h4><p><em>How to preserve original image aspect ratio and display things fullscreen in both desktop and mobile:</em></p><pre>const Wrapper = <strong><em>styled</em></strong>.div`<br>  position: fixed;<br>  top: 0;<br>  left: 0;<br>  width: 100%;<br>  height: 100%;<br>  display: flex;<br>  justify-content: center;<br>  align-items: center;<br>  pointer-events: none;<br><br>  &amp;.shown {<br>    pointer-events: initial;<br>  }<br>`;<br><br>const Image = <strong><em>styled</em></strong>.img`<br>  // Important part<br>  @media (orientation: landscape) {<br>    height: 100%;<br>  }<br>  @media (orientation: portrait) {<br>    width: 100%;<br>  }<br><br>  max-width: 80vw;<br>  max-height: 80vh;<br>`;</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ded7e0ce9163" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Node.js: writing shell scripts using modern JavaScript instead of Bash]]></title>
            <link>https://medium.com/cloudboost/node-js-writing-shell-scripts-using-modern-javascript-instead-of-bash-774e0859f965?source=rss-ca6ca0d4d6e6------2</link>
            <guid isPermaLink="false">https://medium.com/p/774e0859f965</guid>
            <category><![CDATA[bash]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[tutorial]]></category>
            <dc:creator><![CDATA[Vladimir Tolstikov]]></dc:creator>
            <pubDate>Mon, 18 Nov 2019 14:01:02 GMT</pubDate>
            <atom:updated>2020-01-24T08:16:04.867Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kQR_AocWuFiXMtHMctjUYA.gif" /></figure><p>After another case of the need of making changes in Bash script and battling with its syntax and docs I banged myself: “Enough! Let’s use the power of JavaScript!”. Since the rest of codebase in project using JS, that seemed a good idea.</p><p><em>All the code below will work mostly only in Unix-like OSes as MacOS and Linux.</em></p><h3>Requirements to solution</h3><ul><li>lightweight, no deps or minimum</li><li>easy to write</li><li>same console output as if using Bash</li></ul><h3>Investigation</h3><p>I started from searching inside Node.js API. exec appeared to be not so good choice for several reasons, but <a href="https://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options"><strong>spawn</strong></a> seemed promising because of one important feature: ability to inherit stdio and immediately echo all the command output right to the console during command execution when using {stdio: &#39;inherit&#39;} in options.</p><p>Also we will need an easy way to parse possible script params as for example --skip-ios or -d 1 which is not a simple task. For all that we will use <a href="http://yargs.js.org/"><strong>Yargs</strong></a> — Node.js library which helps not only to easily parse passed console params but also allows to check for required params and build structured help menu for your shell script in no time.</p><h3>Implementation</h3><p>Since spawn API method requires bunch of boilerplate code, we’re going to write helper wrapper function so can use it easily. It’s 2K19 and we ofc will use native <strong>Promises</strong> and <strong>async/await</strong> to streamline our code. Also I prefer TypeScript, but using it here would be not so lightweight, so passing with it for now.</p><p>After several iterations and debugging, we have next (as utils.js file):</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d1f2184a21be0670a5d00247e31a8382/href">https://medium.com/media/d1f2184a21be0670a5d00247e31a8382/href</a></iframe><p>With that, shell commands can be executed as simple as:<br>await exec(&#39;rm -rf ./dist&#39;);</p><p>capture option can be used to capture command output:<br>const date = (await exec(&#39;date&#39;, {capture: true})).data;<br>console.log(date);</p><p>echo option can be used for debugging or making your scripts a bit more verbose.</p><p>Exported function can be used in next way to write your custom shell scripts (as deploy.js file):</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3f8fcef9499d34f79c4fb24f85a705c2/href">https://medium.com/media/3f8fcef9499d34f79c4fb24f85a705c2/href</a></iframe><p><em>Note: you’ll need to install Yargs with </em><em>npm install yargs --save-dev</em></p><p>Code above is self-explanatory. As you see, all is simple now with use async/await and you can use full power of JavaScript there without having headache :)</p><p>Result script can be added to scripts section of package.json as:</p><pre>&quot;deploy&quot;: &quot;node ./scripts/deploy.js&quot;,<br>&quot;deploy:integration&quot;: &quot;npm run deploy -- integration&quot;,<br>&quot;deploy:staging&quot;: &quot;npm run deploy -- staging&quot;,<br>&quot;deploy:production&quot;: &quot;npm run deploy -- production&quot;</pre><p>and can be used in a next way:</p><pre>yarn deploy:integration<br>yarn deploy integration<br>yarn deploy integration --skip-build<br>yarn deploy --help</pre><pre>npm run deploy:integration<br>npm run deploy -- integration<br>npm run deploy -- integration --skip-build<br>npm run deploy -- --help</pre><p>As you see, passing of additional params is more intuitive when using Yarn. I hope that helped and will speedup your development. Thanks :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=774e0859f965" width="1" height="1" alt=""><hr><p><a href="https://medium.com/cloudboost/node-js-writing-shell-scripts-using-modern-javascript-instead-of-bash-774e0859f965">Node.js: writing shell scripts using modern JavaScript instead of Bash</a> was originally published in <a href="https://medium.com/cloudboost">CloudBoost</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Quick introduction to React for Angular developers]]></title>
            <link>https://medium.com/cloudboost/fast-introduction-to-react-for-angular-2-4-developers-4465e1621cf7?source=rss-ca6ca0d4d6e6------2</link>
            <guid isPermaLink="false">https://medium.com/p/4465e1621cf7</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[angular-4]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Vladimir Tolstikov]]></dc:creator>
            <pubDate>Thu, 30 Nov 2017 07:44:16 GMT</pubDate>
            <atom:updated>2018-10-16T08:56:04.420Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*yq7TPrTheULIcxwfTD96SA.png" /></figure><p><em>Disclaimer: that’s not another holy war article about “what’s better?”, that’s an article which draws parallels between Angular 2 and React concepts and should help to quickly start with React if you know Angular 2.</em></p><h3>Core differences</h3><p>Main difference between Angular 2 and React lies in the fact that Angular 2 is a framework, but React is an UI library. I.e. to build common application with React you will need to use other libraries, which will provide:</p><ul><li>routing (react-router)</li><li>state management (Redux, MobX .. but you can go without state manager (not really recommended). Yes, in Angular it’s not built-in too, you can use great <a href="https://medium.com/u/5df0f4e36e72">@ngrx</a> or just services)</li><li>form validation (react-validation, formsy-react, redux-form)</li><li>animations</li><li>HTTP abstraction (or just use fetch)</li><li>i18n</li></ul><p>Angular 2+ provides (but doesn’t require) most of them right from the box and has a way, official examples and style guides on how to use all that. Angular’s conception is more monolithic and SPA-related, React itself is small and fast and can be used not only for SPA but to “animate” only parts of classic server-side-rendered application (PHP/Ruby/Python-based or others), near as old AngularJS. So they even can be used together.</p><p>On all that I have next opinion atm (I’m a fan (but not fanatic) of Angular):</p><ul><li>if you need to build a big, well-structured, enterprise-level SPA — Angular 2+ is a good choice</li><li>if you need to build something small, or something fast-loaded (if bundle size is too critical for you), or your app is not a SPA — then you better check React/Preact/VueJS (last one is possibly best these days tbh)</li></ul><p>After I tried React, I now see why it’s so popular and that’s not only because of “Facebook use it” — reason is in its initial simplicity. That’s like “modern jQuery” of our days (there’s nothing mocking in these words, vice versa), you can learn it pretty quick if you’re good JavaScript developer (and if “not good” too so that could become an issue in future tbh, barrier to entry is too low).</p><h3>Where to start?</h3><p>I really recommend to start from <a href="https://reactjs.org/docs/hello-world.html">official documentation and Docs section in it</a>, it’s not so big, you can get it all in one day. Documentation is very good and straightforward, also it mentions all core concepts and good practices as “pure components” and “single source of truth” which should be embraced and followed during development to have “bugs-free” (haha), “easily testable” and “simple-to-understand” app.</p><h3>What about TypeScript? / Quick start</h3><p>As good Angular 2+ developer you’ll want to use TypeScript with React as well. Here’s very good description on that <a href="https://github.com/Microsoft/TypeScript-React-Starter">https://github.com/Microsoft/TypeScript-React-Starter</a> which uses official React boilerplate (called create-react-app)</p><h3>What about CLI/scaffolding?</h3><p>React hasn’t official CLI and it almost not needed. All useful scripts already exposed to package.json.</p><h3>What about project structure?</h3><p>React docs doesn’t contain that info, because it’s a library, don’t you forget? :) As I found, next structure mostly used (inside src folder):</p><ul><li>actions — your Redux actions (if you use it)</li><li>components — your components (mostly pure)</li><li>containers — your high-level components like pages/screens</li><li>reducers — your Redux reducers (if you use it)</li><li>store/stores — your Redux store definition or MobX stores (if you use them)</li><li>styles — your styles for whole app (using Webpack imports)</li></ul><p>But it’s not strict. You can use components folder without containers and nest your components and subcomponents respectively in subfolders as kind of modules in Angular world. Good examples:</p><ul><li><a href="https://github.com/alik0211/pokedex/tree/master/src">https://github.com/alik0211/pokedex/tree/master/src</a> (Redux)</li><li><a href="https://github.com/gothinkster/react-mobx-realworld-example-app/tree/master/src/components">https://github.com/gothinkster/react-mobx-realworld-example-app/tree/master/src/components</a> (MobX)</li></ul><h3>What about components?</h3><p>If you read official documentation, you should know much about it already. Components in React are just (ideally “pure”) functions which getting data as params and returning HTML/UI as a result. Here we have next analogues with Angular:</p><ul><li><strong>selector</strong>—React component’s class name is your selector. Should start with capital letter. Interesting thing that <strong>you will not find that “custom tag”</strong> in final DOM as in usual Angular app, because components just a functions which render stuff with render method, they don’t create additional DOM nodes. Could be very handy if you have “ready-to-go” template, because it will not break layout with component tags.</li><li><strong>@Input()</strong> — React component has props for that purpose, that’s an object which contains all inputs for a component, they’re not separate as in Angular. props should not be mutated, component has state for that purpose (which should be mutated through setState, not directly)</li><li><strong>@Output()</strong>—React hasn’t that concept separately, you should pass your parent callback into props of your child component and call it explicitly inside child component. Still looks a bit sic to me and not kinda in accordance with my understanding of SOLID.</li><li><strong>EventEmitter</strong>—not used, see above</li><li><strong>@ViewChild</strong>—React has special keyword ref for that, but it should be avoided if possible in favor of props.</li><li><strong>ngOnInit</strong> and other hooks—<a href="https://reactjs.org/docs/react-component.html#the-component-lifecycle">https://reactjs.org/docs/react-component.html#the-component-lifecycle</a></li></ul><h3>What about templates?</h3><p>React uses <a href="https://reactjs.org/docs/jsx-in-depth.html"><strong>JSX</strong></a> — own syntax extension to JavaScript, layout lives together with your code and mixed with it tight in one file. Initially it may look very messy, but if you do it right you will see that it shines. IDE nicely helps with it. Because we’re using TypeScript, files will have .tsx extension.</p><h3>What about SCSS/styles?</h3><p>Official React create-react-app boilerplate goes without built-in support for SASS/SCSS or other preprocessors, but they have <a href="https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#adding-a-css-preprocessor-sass-less-etc">documentation how to set it up</a> without ejecting Webpack config (or you can setup your IDE to build it with watcher, but that’s not 100% bulletproof when building). You still will need to import your CSS files with import as any other files inside you component, webpack will take care for they properly included. If you want to import SCSS files directly without those “crutches”, you’ll need to eject your Webpack config and add proper rules into it.</p><p>No documentation on where it should be placed, I think better to keep component-related styles near components.</p><p>UPD: check <a href="https://www.styled-components.com/">https://www.styled-components.com/</a> library which uses <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#Tagged_templates">tagged templates</a> ES2015 syntax which allows to use classic CSS syntax to write your styles and prevents unnecessary styles intersection in different components as in Angular.</p><h3>What about routing?</h3><p>You’ll need to use <a href="https://reacttraining.com/react-router/"><strong>react-router</strong></a><strong> </strong>— most popular one. You will be stunned by its simplicity and declarative nature, because you define routes as components (as almost all in React) right in your layout. Even redirects done by showing/rendering &lt;Redirect …/&gt; component in your layout in proper moment of time.</p><p>UPD: <a href="https://router5.js.org/">Router5</a> may provide better, more-structured way to organize whole routing and solve problem with links building consistency as well.</p><h3>What about services?</h3><p>You can use pure ES6 classes for that, BUT I would really <strong>recommend to use MobX</strong> as base for services and you’re getting state manager in the same time as well — BOOM! With MobX you will be able to write Angular-like services, called stores here, with own kind of observables which brings reactive features into React rendering and not only rendering… Just remember to mutate state only with “actions” to stay clean. Good example of the service written using MobX is <a href="https://github.com/gothinkster/react-mobx-realworld-example-app/blob/master/src/stores/articlesStore.js">here</a> (you don’t need to use $req stuff from there). Also check <a href="https://mobx.js.org/refguide/observer-component.html">here</a> on inject, so you don’t need to pass stores through props all down the hierarchy till components where you need them, but mind: passing data through props (data, not stores) is still preferred way to pass data to sub-components.</p><p>MobX is written on TypeScript which is a plus for us and using great power of decorators to significantly reduce boilerplate code (in comparison to Redux).</p><h3>What about modules?</h3><p>There’s no modules. See “What about project structure?”</p><h3>What about state management?</h3><p>I think you heard about <a href="https://redux.js.org/"><strong>Redux</strong></a> already and you will be familiar with it if used <a href="https://medium.com/u/5df0f4e36e72">@ngrx</a>/store, but I still recommend to use <a href="https://mobx.js.org/index.html"><strong>MobX</strong></a> as I stated above, it’s really cool and Angularish!</p><p>UPD: these days more people look in a way of GraphQL which may replace whole Redux for your app. Check <a href="https://www.google.com/search?q=graphql+state+management&amp;oq=graphql+state+mana&amp;aqs=chrome.0.0j69i60j69i57j0.3661j0j7&amp;sourceid=chrome&amp;ie=UTF-8">those links</a> and official docs on local state management. Also I discovered MobX-based <a href="https://github.com/mobxjs/mobx-state-tree">mobx-state-tree</a> which could be used as well. So, stay open-minded, Redux is not a silver bullet.</p><h3>What about lazy-loading/code splitting?</h3><p><a href="https://reacttraining.com/react-router/"><strong>react-router</strong></a> has an article for that: <a href="https://reacttraining.com/react-router/web/guides/code-splitting">https://reacttraining.com/react-router/web/guides/code-splitting</a>.</p><h3>What about DI?</h3><p>React doesn’t use DI by default and there’s no need for it mostly. MobX has providers mechanism which can be used as DI for almost any class/object.</p><p>When you need to unit-test component with child components/sub-components you can use Enzyme with its “Shallow Rendering API” so there will be no need to mock sub-components where DI usually used in other paradigms, and if you follow good practices on pure components, testing should not be an issue.</p><h3>What about Unit-tests?</h3><p><a href="https://facebook.github.io/jest/"><strong>Jest</strong></a> is used widely there (with built-in Jasmine), together with <a href="http://airbnb.io/enzyme/"><strong>Enzyme</strong></a> and all that performs well.</p><p>If you’ll struggle with “how can I test component which uses async data retrieval in componentDidMount or async setState” and crashing Jest — check <a href="https://stackoverflow.com/questions/41792927/jest-tests-cant-fail-within-setimmediate-or-process-nexttick-callback/47760009#47760009">my answer on StackOverflow</a>, that’s really tricky issue.</p><h3>What about webpack config?</h3><p>You can get it by using yarn eject.</p><h3>What about environment configs?</h3><p>You can find about that <a href="https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#adding-custom-environment-variables">here</a>, there’s no easy export of environment config right from the box, you’ll need to do that manually or use those ENV variables “as is” in plain way.</p><h3>What about i18n/Internationalization?</h3><p>That’s still open question for me, there are many libs for that. Best I can find, which is close to widely used @ngx-translate, is that one <a href="https://github.com/i18next/react-i18next">https://github.com/i18next/react-i18next</a>.</p><h3>That’s it for now</h3><p>I can say after Angular you will find that React is a “walk in the park”, it’s easier to learn and that’s why it’s so popular. It has lack of “official” conception for building actual apps in comparison to Angular and that has cons and pros in the same moment.</p><p>If I missed something important or was wrong in some details — write in comments.Thanks and happy coding :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4465e1621cf7" width="1" height="1" alt=""><hr><p><a href="https://medium.com/cloudboost/fast-introduction-to-react-for-angular-2-4-developers-4465e1621cf7">Quick introduction to React for Angular developers</a> was originally published in <a href="https://medium.com/cloudboost">CloudBoost</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to merge d.ts typings with dts-bundle and Webpack]]></title>
            <link>https://medium.com/@vladimirtolstikov/how-to-merge-d-ts-typings-with-dts-bundle-and-webpack-e8903d699576?source=rss-ca6ca0d4d6e6------2</link>
            <guid isPermaLink="false">https://medium.com/p/e8903d699576</guid>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[npm]]></category>
            <category><![CDATA[webpack]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Vladimir Tolstikov]]></dc:creator>
            <pubDate>Fri, 02 Dec 2016 10:32:16 GMT</pubDate>
            <atom:updated>2018-05-18T12:27:50.611Z</atom:updated>
            <content:encoded><![CDATA[<p>Hi there! If you’re using TypeScript in your JS-workflow you should already know about d.ts files where 3rd-party libraries store public definitions for your IDE and TypeScript compiler could do their job. Today we will talk about how to generate typings for your custom npm library. I write this because not found solution on the internet, hope that will help to someone else too :)</p><p>Ok, straight to the business. Hope you already setted up Webpack to work with TypeScript, that article not about it, but you can check config in the end if needed.</p><p>Firstly, enable d.ts file emission by ts-compiler in tsconfig.json</p><pre>{<br>  &quot;compilerOptions&quot;: {<br>    &quot;declaration&quot;: <strong>true</strong>,<br>// ...</pre><p>It will create one file per .ts source, but we need one file. Here’s <strong>dts-bundle</strong> join the game. Install it first from npm</p><pre>npm install dts-bundle --save-dev</pre><p>Now we need to link it with Webpack. To do that I wrote short Webpack-plugin right in webpack.config.js. Check DtsBundlePlugin and how it added to plugins list right in my config below.</p><pre><strong>var </strong>webpack = require(&#39;webpack&#39;),<br>    path = require(&#39;path&#39;),<br>    yargs = require(&#39;yargs&#39;);<br><br><strong>var </strong>libraryName = &#39;CBAnalytics&#39;,<br>    plugins = [],<br>    isProductionBuild = yargs.argv.mode === &#39;build&#39;;<br><br><strong>if </strong>(isProductionBuild) {<br>  plugins.push(<strong>new </strong>DtsBundlePlugin());<br>  plugins.push(<strong>new </strong>webpack.optimize.UglifyJsPlugin({ minimize: <strong>true </strong>}));<br>}<br><br><strong>var </strong>entry = {};<br>entry[libraryName] = __dirname + &#39;/src/index.ts&#39;;<br>entry[libraryName + &#39;.min&#39;] = __dirname + &#39;/src/index.ts&#39;;<br><br><strong>var </strong>config = {<br>  entry: entry,<br>  devtool: isProductionBuild ? <strong>null </strong>: &#39;source-map&#39;,<br>  output: {<br>    path: path.join(__dirname),<br>    filename: &quot;[name].js&quot;,<br>    library: libraryName,<br>    libraryTarget: &#39;umd&#39;,<br>    umdNamedDefine: <strong>true<br>  </strong>},<br>  module: {<br>    preLoaders: [<br>      { test: /\.tsx?$/, loader: &#39;tslint&#39;, exclude: /node_modules/ }<br>    ],<br>    loaders: [<br>      { test: /\.tsx?$/, loader: &#39;ts&#39;, exclude: /node_modules/ }<br>    ]<br>  },<br>  resolve: {<br>    root: path.resolve(&#39;./src&#39;),<br>    extensions: [ &#39;&#39;, &#39;.js&#39;, &#39;.ts&#39;, &#39;.jsx&#39;, &#39;.tsx&#39; ]<br>  },<br>  plugins: plugins,<br><br>  // Individual Plugin Options<br>  tslint: {<br>    emitErrors: <strong>true</strong>,<br>    failOnHint: <strong>true<br>  </strong>}<br>};<br><br>module.exports = config;<br><br><br><strong>function </strong>DtsBundlePlugin(){}<br>DtsBundlePlugin.prototype.apply = <strong>function </strong>(compiler) {<br>  compiler.plugin(&#39;done&#39;, <strong>function</strong>(){<br>    <strong>var </strong>dts = require(&#39;dts-bundle&#39;);<br><br>    dts.bundle({<br>      name: libraryName,<br>      main: &#39;src/index.d.ts&#39;,<br>      out: &#39;../index.d.ts&#39;,<br>      removeSource: <strong>true</strong>,<br>      outputAsModuleFolder: <strong>true </strong>// to use npm in-package typings<br>    });<br>  });<br>};</pre><p>Now one single .d.ts file will be generated in root of the project. One thing remains — need to add that d.ts to package.json (<a href="http://www.typescriptlang.org/docs/handbook/declaration-files/publishing.html">official doc on TypeScript npm publishing</a>)</p><pre>{<br>  &quot;name&quot;: &quot;cb-analytics&quot;,<br>  &quot;version&quot;: &quot;1.0.0&quot;,<br>  &quot;description&quot;: &quot;&quot;,<br>  &quot;main&quot;: &quot;CBAnalytics.min.js&quot;,<br>  <strong>&quot;types&quot;: &quot;index.d.ts&quot;,</strong><br>  &quot;scripts&quot;: {<br>    &quot;start&quot;: &quot;webpack --progress --colors --watch&quot;,<br>    &quot;build&quot;: &quot;webpack --mode=build&quot;,<br>    &quot;test&quot;: &quot;karma start&quot;<br>  },<br>...</pre><p>That’s it, I hope nothing missed :) If you will not use npm typings definition, you need to set <em>outputAsModuleFolder</em> to <em>false</em>. <em>removeSource</em> flag should remove generated d.ts files, but if they’re still there you can ignore them in .gitignore with</p><pre>*.d.ts<br># Exclude root d.ts<br>!/*.d.ts</pre><p>or leave or delete them in another step — your choice.</p><p>Happy coding :)</p><p><strong>UPD:<br></strong>I see most people need to see how final files/configs look, here they are:</p><blockquote>package.json</blockquote><pre>{<br>  &quot;name&quot;: &quot;cb-analytics&quot;,<br>  &quot;version&quot;: &quot;1.0.0&quot;,<br>  &quot;description&quot;: &quot;&quot;,<br>  &quot;main&quot;: &quot;CBAnalytics.min.js&quot;,<br>  &quot;types&quot;: &quot;index.d.ts&quot;,<br>  &quot;scripts&quot;: {<br>    &quot;start&quot;: &quot;webpack --progress --colors --watch&quot;,<br>    &quot;build&quot;: &quot;webpack --mode=build&quot;,<br>    &quot;test&quot;: &quot;karma start&quot;<br>  },<br>  &quot;keywords&quot;: [],<br>  &quot;author&quot;: &quot;&quot;,<br>  &quot;license&quot;: &quot;ISC&quot;,<br>  &quot;dependencies&quot;: {<br>    &quot;extend&quot;: &quot;^3.0.0&quot;,<br>    &quot;js-cookie&quot;: &quot;^2.1.4&quot;,<br>    &quot;nanoajax&quot;: &quot;^0.4.3&quot;<br>  },<br>  &quot;devDependencies&quot;: {<br>    &quot;@types/extend&quot;: &quot;^2.0.30&quot;,<br>    &quot;@types/jasmine&quot;: &quot;^2.5.38&quot;,<br>    &quot;@types/js-cookie&quot;: &quot;^2.0.28&quot;,<br>    &quot;@types/nanoajax&quot;: &quot;^0.2.29&quot;,<br>    &quot;dts-bundle&quot;: &quot;^0.6.1&quot;,<br>    &quot;jasmine-core&quot;: &quot;^2.5.2&quot;,<br>    &quot;karma&quot;: &quot;^1.3.0&quot;,<br>    &quot;karma-chrome-launcher&quot;: &quot;^2.0.0&quot;,<br>    &quot;karma-cli&quot;: &quot;^1.0.1&quot;,<br>    &quot;karma-jasmine&quot;: &quot;^1.0.2&quot;,<br>    &quot;karma-webpack&quot;: &quot;^1.8.0&quot;,<br>    &quot;ts-loader&quot;: &quot;^1.2.2&quot;,<br>    &quot;tslint&quot;: &quot;^4.0.2&quot;,<br>    &quot;tslint-loader&quot;: &quot;^3.2.0&quot;,<br>    &quot;typescript&quot;: &quot;^2.0.10&quot;,<br>    &quot;webpack&quot;: &quot;^1.13.3&quot;,<br>    &quot;yargs&quot;: &quot;^6.4.0&quot;<br>  }<br>}</pre><blockquote>tsconfig.json</blockquote><pre>{<br>  &quot;compileOnSave&quot;: <strong>false</strong>,<br>  &quot;compilerOptions&quot;: {<br>    &quot;declaration&quot;: <strong>true</strong>,<br>    &quot;jsx&quot;: &quot;react&quot;,<br>    &quot;module&quot;: &quot;commonjs&quot;,<br>    &quot;noImplicitAny&quot;: <strong>true</strong>,<br>    &quot;preserveConstEnums&quot;: <strong>true</strong>,<br>    &quot;removeComments&quot;: <strong>false</strong>,<br>    &quot;sourceMap&quot;: <strong>true</strong>,<br>    &quot;target&quot;: &quot;es5&quot;<br>  },<br>  &quot;exclude&quot;: [<br>    &quot;node_modules&quot;<br>  ]<br>}</pre><blockquote>webpack.config.js</blockquote><pre><strong>var </strong>webpack = require(&#39;webpack&#39;),<br>    path = require(&#39;path&#39;),<br>    yargs = require(&#39;yargs&#39;);</pre><pre><strong>var </strong>libraryName = &#39;CBAnalytics&#39;,<br>    plugins = [],<br>    isProductionBuild = yargs.argv.mode === &#39;build&#39;;</pre><pre><strong>var </strong>entry = {};<br>entry[libraryName] = __dirname + &#39;/src/index.ts&#39;;</pre><pre><strong>if </strong>(isProductionBuild) {<br>  entry[libraryName + &#39;.min&#39;] = __dirname + &#39;/src/index.ts&#39;;<br>  <br>  plugins.push(<strong>new </strong>DtsBundlePlugin());<br>  plugins.push(<strong>new </strong>webpack.optimize.UglifyJsPlugin({<br>    include: /\.min\.js$/,<br>    minimize: <strong>true<br>  </strong>}));<br>}</pre><pre><strong>var </strong>config = {<br>  entry: entry,<br>  devtool: isProductionBuild ? <strong>null </strong>: &#39;source-map&#39;,<br>  output: {<br>    path: path.join(__dirname),<br>    filename: &quot;[name].js&quot;,<br>    library: libraryName,<br>    libraryTarget: &#39;umd&#39;,<br>    umdNamedDefine: <strong>true<br>  </strong>},<br>  module: {<br>    preLoaders: [<br>      { test: /\.tsx?$/, loader: &#39;tslint&#39;, exclude: /node_modules/ }<br>    ],<br>    loaders: [<br>      { test: /\.tsx?$/, loader: &#39;ts&#39;, exclude: /node_modules/ }<br>    ]<br>  },<br>  resolve: {<br>    root: path.resolve(&#39;./src&#39;),<br>    extensions: [ &#39;&#39;, &#39;.js&#39;, &#39;.ts&#39;, &#39;.jsx&#39;, &#39;.tsx&#39; ]<br>  },<br>  plugins: plugins,</pre><pre>  // Individual Plugin Options<br>  tslint: {<br>    emitErrors: <strong>true</strong>,<br>    failOnHint: <strong>true<br>  </strong>}<br>};</pre><pre>module.exports = config;<br></pre><pre><strong>function </strong>DtsBundlePlugin(){}<br>DtsBundlePlugin.prototype.apply = <strong>function </strong>(compiler) {<br>  compiler.plugin(&#39;done&#39;, <strong>function</strong>(){<br>    <strong>var </strong>dts = require(&#39;dts-bundle&#39;);</pre><pre>    dts.bundle({<br>      name: libraryName,<br>      main: &#39;src/index.d.ts&#39;,<br>      out: &#39;../index.d.ts&#39;,<br>      removeSource: <strong>true</strong>,<br>      outputAsModuleFolder: <strong>true </strong>// to use npm in-package typings<br>    });<br>    <br>    // Delete unneeded files<br>    <br>  });<br>};</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e8903d699576" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>