Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,22 @@ Usage: pack [options] <path>

Options:

-h, --help output usage information
-u, --uglify Uglify the project when webpacking
-o, --output <path> Path for output directory
-h, --help output usage information
-u, --uglify Uglify the project when webpacking
-o, --output <path> Path for output directory
-c, --copyToOutput Copy files to output directory
-e, --editConfig <path> 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
Expand Down
1 change: 0 additions & 1 deletion dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ COPY sshd_config /etc/ssh
RUN mkdir -p /home/.azurefunctions/bin

RUN npm i -g azure-functions-core-tools@core --unsafe-perm
RUN mv /home/.azurefunctions/bin/workers/node /home/.azurefunctions/bin/workers/Node

WORKDIR /content

Expand Down
2 changes: 2 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ async function runCli() {
.option("-w, --watch", "Run in watch mode to support local development with 'func host'")
.option("-o, --output <path>", "Path for output directory")
.option("-c, --copyToOutput", "Copy files to output directory")
.option("-e, --editConfig <path>", "Customize webpack config by applying function in this file")
.action(pack);

p.command("*", null, { noHelp: true, isDefault: true })
Expand Down Expand Up @@ -150,6 +151,7 @@ async function pack(name: string, options: any) {
try {
winston.info("Webpacking project");
await WebpackRunner.run({
editConfig: options.editConfig,
ignoredModules: config.ignoredModules,
outputPath,
projectRootPath,
Expand Down
15 changes: 14 additions & 1 deletion src/webpack-runner.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand All @@ -14,6 +15,7 @@ export interface IWebpackRunner {
uglify?: boolean;
watch?: boolean;
ignoredModules?: string[];
editConfig?: string;
}

export class WebpackRunner {
Expand All @@ -38,7 +40,7 @@ export class WebpackRunner {
}

debug("Creating Webpack Configuration");
const config: webpack.Configuration = {
let config: webpack.Configuration = {
entry: packHostPath,
externals: ignoredModules,
node: {
Expand All @@ -65,6 +67,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");
Expand Down