From b41019bd9b09062ab107990779f78b69b9b548a8 Mon Sep 17 00:00:00 2001 From: sis0k0 Date: Mon, 14 May 2018 16:20:03 +0300 Subject: [PATCH 1/2] fix-next: add tsconfig.esm.json to TS projects That will allow the TS apps to be tree-shakeable, too. --- projectFilesManager.js | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/projectFilesManager.js b/projectFilesManager.js index 4fe8750e..09996cc8 100644 --- a/projectFilesManager.js +++ b/projectFilesManager.js @@ -57,21 +57,41 @@ function copyTemplate(templateName, destinationPath) { } function getProjectTemplates(projectDir) { - const templates = {} - const WEBPACK_CONFIG_NAME = "webpack.config.js"; + const TSCONFIG_ESM_NAME = "tsconfig.esm.json"; + + let templates; if (isAngular({projectDir})) { - templates["webpack.angular.js"] = WEBPACK_CONFIG_NAME; - templates["tsconfig.esm.json"] = "tsconfig.esm.json"; + templates = getAngularTemplates(WEBPACK_CONFIG_NAME, TSCONFIG_ESM_NAME); } else if (isTypeScript({projectDir})) { - templates["webpack.typescript.js"] = WEBPACK_CONFIG_NAME; + templates = getTypeScriptTemplates(WEBPACK_CONFIG_NAME, TSCONFIG_ESM_NAME); } else { - templates["webpack.javascript.js"] = WEBPACK_CONFIG_NAME; + templates = getJavaScriptTemplates(WEBPACK_CONFIG_NAME); } return getFullTemplatesPath(projectDir, templates); } +function getAngularTemplates(webpackConfigName, tsconfigName) { + return { + "webpack.angular.js": webpackConfigName, + [tsconfigName]: tsconfigName, + }; +} + +function getTypeScriptTemplates(webpackConfigName, tsconfigName) { + return { + "webpack.typescript.js": webpackConfigName, + [tsconfigName]: tsconfigName, + }; +} + +function getJavaScriptTemplates(webpackConfigName) { + return { + "webpack.javascript.js": webpackConfigName, + }; +} + function getFullTemplatesPath(projectDir, templates) { let updatedTemplates = {}; From ec6b41e10ab4c25dbca9538d8f5668d9f17ffb9a Mon Sep 17 00:00:00 2001 From: sis0k0 Date: Tue, 15 May 2018 10:32:33 +0300 Subject: [PATCH 2/2] refactor(configs/webpack/ts): target tsconfig.esm.json when bundling --- templates/webpack.typescript.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/templates/webpack.typescript.js b/templates/webpack.typescript.js index b42b79de..6f223b11 100644 --- a/templates/webpack.typescript.js +++ b/templates/webpack.typescript.js @@ -166,7 +166,13 @@ module.exports = env => { ] }, - { test: /\.ts$/, use: "awesome-typescript-loader" } + { + test: /\.ts$/, + use: { + loader: "awesome-typescript-loader", + options: { configFileName: "tsconfig.esm.json" }, + } + }, ] }, plugins: [