From 4c1f55c565b474373b03b7b951a83e77b7a0974e Mon Sep 17 00:00:00 2001 From: jan Date: Fri, 19 Jan 2018 16:49:09 +0100 Subject: [PATCH 1/3] disable global.GENTLY --- src/webpack-runner.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/webpack-runner.ts b/src/webpack-runner.ts index dc7de4f..591c92b 100644 --- a/src/webpack-runner.ts +++ b/src/webpack-runner.ts @@ -49,7 +49,9 @@ export class WebpackRunner { libraryTarget: "commonjs2", path: path.join(options.projectRootPath, options.outputPath), }, - plugins: [], + plugins: [ + new webpack.DefinePlugin({ "global.GENTLY": false }), + ], target: "node", }; From 2405b10e973a0e472ee2082b536b195a6c964edd Mon Sep 17 00:00:00 2001 From: jan Date: Tue, 23 Jan 2018 14:49:14 +0100 Subject: [PATCH 2/3] add possibility to specify a function to alter webpack config --- src/main.ts | 2 ++ src/webpack-runner.ts | 19 +++++++++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/main.ts b/src/main.ts index 44d1f5d..ed37536 100644 --- a/src/main.ts +++ b/src/main.ts @@ -22,6 +22,7 @@ async function runCli() { .option("-u, --uglify", "Uglify the project when webpacking") .option("-o, --output ", "Path for output directory") .option("-c, --copyToOutput", "Copy files to output directory") + .option("-e, --editConfig ", "Customize webpack config by applying function exported in this file") .action(pack); p.command("*", null, { noHelp: true, isDefault: true }) @@ -139,6 +140,7 @@ async function pack(name: string, options: any) { try { winston.info("Webpacking project"); await WebpackRunner.run({ + editConfig: options.editConfig, ignoredModules: config.ignoredModules, outputPath, projectRootPath, diff --git a/src/webpack-runner.ts b/src/webpack-runner.ts index 591c92b..2f73e0b 100644 --- a/src/webpack-runner.ts +++ b/src/webpack-runner.ts @@ -1,6 +1,7 @@ import * as debugLib from "debug"; import * as path from "path"; import * as webpack from "webpack"; +import * as winston from "winston"; import { IPackhostGeneratorOptions } from "./"; import { FileHelper } from "./utils"; @@ -12,6 +13,7 @@ export interface IWebpackRunner { outputPath?: string; uglify?: boolean; ignoredModules?: string[]; + editConfig?: string; } export class WebpackRunner { @@ -36,7 +38,7 @@ export class WebpackRunner { } debug("Creating Webpack Configuration"); - const config: webpack.Configuration = { + let config: webpack.Configuration = { entry: oldPath, externals: ignoredModules, node: { @@ -49,9 +51,7 @@ export class WebpackRunner { libraryTarget: "commonjs2", path: path.join(options.projectRootPath, options.outputPath), }, - plugins: [ - new webpack.DefinePlugin({ "global.GENTLY": false }), - ], + plugins: [], target: "node", }; @@ -64,6 +64,17 @@ export class WebpackRunner { } } + try { + if (options.editConfig) { + const customizeFunctionPath = path.join(options.projectRootPath, options.editConfig); + const customizeFunction = require(customizeFunctionPath); + config = customizeFunction(config, webpack); + } + } catch (e) { + winston.error(e); + throw new Error("Could not apply customize function"); + } + debug("Creating Webpack instance"); const compiler = webpack(config); debug("Started webpack"); From 6a3b5e295841016efd53e6634ae5d3d3bd507db2 Mon Sep 17 00:00:00 2001 From: jan Date: Tue, 23 Jan 2018 15:03:11 +0100 Subject: [PATCH 3/3] update editConfig description and readme --- README.md | 19 ++++++++++++++++--- src/main.ts | 2 +- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 7d0112d..28e81e8 100644 --- a/README.md +++ b/README.md @@ -82,9 +82,22 @@ Usage: pack [options] Options: - -h, --help output usage information - -u, --uglify Uglify the project when webpacking - -o, --output Path for output directory + -h, --help output usage information + -u, --uglify Uglify the project when webpacking + -o, --output Path for output directory + -c, --copyToOutput Copy files to output directory + -e, --editConfig Customize webpack config by applying function in this file +``` + +The `editConfig` option will let you specify a js file containing a function to alter the webpack configuration. + +``` +// $root/webpack.config.js + +module.exports = function(config, webpack) { + config.plugins.push(new webpack.DefinePlugin({ "global.GENTLY": false })); + return config; +} ``` ### funcpack.config.json diff --git a/src/main.ts b/src/main.ts index ed37536..ec2e0e7 100644 --- a/src/main.ts +++ b/src/main.ts @@ -22,7 +22,7 @@ async function runCli() { .option("-u, --uglify", "Uglify the project when webpacking") .option("-o, --output ", "Path for output directory") .option("-c, --copyToOutput", "Copy files to output directory") - .option("-e, --editConfig ", "Customize webpack config by applying function exported in this file") + .option("-e, --editConfig ", "Customize webpack config by applying function in this file") .action(pack); p.command("*", null, { noHelp: true, isDefault: true })