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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ By default the plugin will look for a `webpack.config.js` in the service root. Y
custom:
webpack:
config: ./path/to/config/file.js
typescript: true # set to true if your project uses TypeScript and have configured the appropriate Webpack loader, defaults to false
```

The `entry` and `output` objects are set by the plugin.
Expand Down
3 changes: 2 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ class ServerlessPluginWebpack {
webpackConfig,
this.originalServicePath,
webpackDefaultOutput,
webpackFolder
webpackFolder,
this.custom.typescript,
));
}

Expand Down
4 changes: 2 additions & 2 deletions src/lib/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ const setPackage = R.pipe(
R.assoc('individually', true)
);

const fnPath = R.compose(R.replace(/\.[^.]+$/, '.js'), R.prop('handler'));
const fnPath = extension => R.compose(R.replace(/\.[^.]+$/, extension), R.prop('handler'));

const setFnsPackage = R.map(R.pipe(
R.when(R.prop('package'), R.over(R.lensProp('package'), makePackageRelative)),
R.converge(
R.over(R.lensPath(['package', 'include'])),
[R.compose(R.append, fnPath), R.identity]
[R.compose(R.append, fnPath('.js')), R.identity]
)
));

Expand Down
12 changes: 7 additions & 5 deletions src/lib/wpack.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ const service = require('./service');
* Sets webpack entry
* @param {object} fn Serverless function object
* @param {string} servicePath Serverless service path
* @param {boolean} useTypeScript Use .ts extension
* @returns {object} Webpack configuration
*/
const setEntry = (fn, servicePath) =>
const setEntry = (fn, servicePath, useTypeScript) =>
R.assoc(
'entry',
R.objOf(
service.fnPath(fn),
path.join(servicePath, service.fnPath(fn))
service.fnPath('.js')(fn),
path.join(servicePath, service.fnPath(useTypeScript ? '.ts' : '.js')(fn))
)
);

Expand All @@ -40,13 +41,14 @@ const setOutput = (defaultOutput, outputPath) =>
* @param {string} servicePath Serverless service path
* @param {object} defaultOutput Webpack default output object
* @param {string} folder Webpack output folder
* @param {boolean} useTypeScript Use .ts extension
* @returns {array} Array of webpack configurations
*/
const createConfigs = (fns, config, servicePath, defaultOutput, folder) =>
const createConfigs = (fns, config, servicePath, defaultOutput, folder, useTypeScript) =>
R.map(
fn =>
R.pipe(
setEntry(fn, servicePath),
setEntry(fn, servicePath, useTypeScript),
setOutput(defaultOutput, path.join(servicePath, folder))
)(config),
R.values(fns)
Expand Down