From 26100eea01d4f79ea08a72b23f32cffbe49c68cc Mon Sep 17 00:00:00 2001 From: Simone Taeggi Date: Fri, 29 Jul 2022 16:58:21 +0200 Subject: [PATCH 1/4] evaluate the webpack.config.ts file and compile the file when we build the typescript project example --- .../core/admin/utils/get-custom-webpack-config.js | 13 +++++++++---- .../lib/resources/json/ts/tsconfig-server.json.js | 2 -- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/packages/core/admin/utils/get-custom-webpack-config.js b/packages/core/admin/utils/get-custom-webpack-config.js index 8a1d59b432..258ebb231d 100644 --- a/packages/core/admin/utils/get-custom-webpack-config.js +++ b/packages/core/admin/utils/get-custom-webpack-config.js @@ -8,13 +8,18 @@ const fs = require('fs-extra'); const getWebpackConfig = require('../webpack.config'); const getCustomWebpackConfig = (dir, config) => { - const adminConfigPath = path.join(dir, 'src', 'admin', 'webpack.config.js'); + const adminConfigPathJS = path.join(dir, 'src', 'admin', 'webpack.config.js'); + const adminConfigPathTS = path.join(dir, 'src', 'admin', 'webpack.config.ts'); let webpackConfig = getWebpackConfig(config); - if (fs.existsSync(adminConfigPath)) { - const webpackAdminConfig = require(path.resolve(adminConfigPath)); - + if (fs.existsSync(adminConfigPathJS) || fs.existsSync(adminConfigPathTS)) { + let webpackAdminConfig; + if (fs.existsSync(adminConfigPathJS)) { + webpackAdminConfig = require(path.resolve(adminConfigPathJS)); + } else { + webpackAdminConfig = require(path.resolve(adminConfigPathTS)); + } if (_.isFunction(webpackAdminConfig)) { // Expose the devServer configuration if (config.devServer) { diff --git a/packages/generators/app/lib/resources/json/ts/tsconfig-server.json.js b/packages/generators/app/lib/resources/json/ts/tsconfig-server.json.js index 0fd1c07e95..f93c39fa27 100644 --- a/packages/generators/app/lib/resources/json/ts/tsconfig-server.json.js +++ b/packages/generators/app/lib/resources/json/ts/tsconfig-server.json.js @@ -22,8 +22,6 @@ module.exports = () => ({ '.cache/', '.tmp/', - // Do not include admin files in the server compilation - 'src/admin/', // Do not include test files '**/*.test.ts', // Do not include plugins in the server compilation From 807eabb356a12b5f5728a057c81938c8d553ed53 Mon Sep 17 00:00:00 2001 From: Simone Taeggi Date: Wed, 3 Aug 2022 10:28:35 +0200 Subject: [PATCH 2/4] revert to the original version because we want to use just javascript files for the webpack config --- .../core/admin/utils/get-custom-webpack-config.js | 12 +++--------- .../lib/resources/json/ts/tsconfig-server.json.js | 3 ++- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/packages/core/admin/utils/get-custom-webpack-config.js b/packages/core/admin/utils/get-custom-webpack-config.js index 258ebb231d..a045487918 100644 --- a/packages/core/admin/utils/get-custom-webpack-config.js +++ b/packages/core/admin/utils/get-custom-webpack-config.js @@ -8,18 +8,12 @@ const fs = require('fs-extra'); const getWebpackConfig = require('../webpack.config'); const getCustomWebpackConfig = (dir, config) => { - const adminConfigPathJS = path.join(dir, 'src', 'admin', 'webpack.config.js'); - const adminConfigPathTS = path.join(dir, 'src', 'admin', 'webpack.config.ts'); + const adminConfigPath = path.join(dir, 'src', 'admin', 'webpack.config.js'); let webpackConfig = getWebpackConfig(config); - if (fs.existsSync(adminConfigPathJS) || fs.existsSync(adminConfigPathTS)) { - let webpackAdminConfig; - if (fs.existsSync(adminConfigPathJS)) { - webpackAdminConfig = require(path.resolve(adminConfigPathJS)); - } else { - webpackAdminConfig = require(path.resolve(adminConfigPathTS)); - } + if (fs.existsSync(adminConfigPath)) { + const webpackAdminConfig = require(path.resolve(adminConfigPath)); if (_.isFunction(webpackAdminConfig)) { // Expose the devServer configuration if (config.devServer) { diff --git a/packages/generators/app/lib/resources/json/ts/tsconfig-server.json.js b/packages/generators/app/lib/resources/json/ts/tsconfig-server.json.js index f93c39fa27..d22c84c488 100644 --- a/packages/generators/app/lib/resources/json/ts/tsconfig-server.json.js +++ b/packages/generators/app/lib/resources/json/ts/tsconfig-server.json.js @@ -21,7 +21,8 @@ module.exports = () => ({ 'dist/', '.cache/', '.tmp/', - + // Do not include admin files in the server compilation + 'src/admin/', // Do not include test files '**/*.test.ts', // Do not include plugins in the server compilation From 16338ad84bf6ff383ef4d0d79442f7e525833341 Mon Sep 17 00:00:00 2001 From: Simone Taeggi Date: Wed, 3 Aug 2022 11:56:23 +0200 Subject: [PATCH 3/4] replace the ts webpack config file with the js version --- .../{webpack.config.example.ts => webpack.config.example.js} | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) rename packages/generators/app/lib/resources/files/ts/src/admin/{webpack.config.example.ts => webpack.config.example.js} (65%) diff --git a/packages/generators/app/lib/resources/files/ts/src/admin/webpack.config.example.ts b/packages/generators/app/lib/resources/files/ts/src/admin/webpack.config.example.js similarity index 65% rename from packages/generators/app/lib/resources/files/ts/src/admin/webpack.config.example.ts rename to packages/generators/app/lib/resources/files/ts/src/admin/webpack.config.example.js index b3ef42fa7a..1ca45c2166 100644 --- a/packages/generators/app/lib/resources/files/ts/src/admin/webpack.config.example.ts +++ b/packages/generators/app/lib/resources/files/ts/src/admin/webpack.config.example.js @@ -1,4 +1,7 @@ -export default (config, webpack) => { +'use strict'; + +/* eslint-disable no-unused-vars */ +module.exports = (config, webpack) => { // Note: we provide webpack above so you should not `require` it // Perform customizations to webpack config // Important: return the modified config From c232a8e8146c835af9090df7cf268f83e7b74b8c Mon Sep 17 00:00:00 2001 From: Simone Taeggi Date: Wed, 3 Aug 2022 12:00:16 +0200 Subject: [PATCH 4/4] revert the empty lines --- packages/core/admin/utils/get-custom-webpack-config.js | 1 + .../generators/app/lib/resources/json/ts/tsconfig-server.json.js | 1 + 2 files changed, 2 insertions(+) diff --git a/packages/core/admin/utils/get-custom-webpack-config.js b/packages/core/admin/utils/get-custom-webpack-config.js index a045487918..8a1d59b432 100644 --- a/packages/core/admin/utils/get-custom-webpack-config.js +++ b/packages/core/admin/utils/get-custom-webpack-config.js @@ -14,6 +14,7 @@ const getCustomWebpackConfig = (dir, config) => { if (fs.existsSync(adminConfigPath)) { const webpackAdminConfig = require(path.resolve(adminConfigPath)); + if (_.isFunction(webpackAdminConfig)) { // Expose the devServer configuration if (config.devServer) { diff --git a/packages/generators/app/lib/resources/json/ts/tsconfig-server.json.js b/packages/generators/app/lib/resources/json/ts/tsconfig-server.json.js index d22c84c488..0fd1c07e95 100644 --- a/packages/generators/app/lib/resources/json/ts/tsconfig-server.json.js +++ b/packages/generators/app/lib/resources/json/ts/tsconfig-server.json.js @@ -21,6 +21,7 @@ module.exports = () => ({ 'dist/', '.cache/', '.tmp/', + // Do not include admin files in the server compilation 'src/admin/', // Do not include test files