Skip to content

Commit 9d890ce

Browse files
committed
TypeScript support
1 parent 2fa7960 commit 9d890ce

4 files changed

Lines changed: 13 additions & 9 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ By default the plugin will look for a `webpack.config.js` in the service root. Y
3838
custom:
3939
webpack:
4040
config: ./path/to/config/file.js
41+
typescript: true # set to true if your project uses TypeScript and have configured the appropriate Webpack loader, defaults to false
4142
```
4243

4344
The `entry` and `output` objects are set by the plugin.

src/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ class ServerlessPluginWebpack {
6262
webpackConfig,
6363
this.originalServicePath,
6464
webpackDefaultOutput,
65-
webpackFolder
65+
webpackFolder,
66+
this.custom.typescript,
6667
)
6768
);
6869
}
@@ -87,7 +88,7 @@ class ServerlessPluginWebpack {
8788
}
8889

8990
clean() {
90-
return fs.remove(path.join(this.originalServicePath, webpackFolder));
91+
// return fs.remove(path.join(this.originalServicePath, webpackFolder));
9192
}
9293
}
9394

src/lib/service.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ const setPackage = R.pipe(
1212
R.assoc('individually', true)
1313
);
1414

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

1717
const setFnsPackage = R.map(
1818
R.pipe(
1919
R.when(R.prop('package'), R.over(R.lensProp('package'), makePackageRelative)),
2020
R.converge(
2121
R.over(R.lensPath(['package', 'include'])),
22-
[R.compose(R.append, fnPath), R.identity]
22+
[R.compose(R.append, fnPath('.js')), R.identity]
2323
)
2424
)
2525
);

src/lib/wpack.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@ const service = require('./service');
77
* Sets webpack entry
88
* @param {object} fn Serverless function object
99
* @param {string} servicePath Serverless service path
10+
* @param {boolean} useTypeScript Use .ts extension
1011
* @returns {object} Webpack configuration
1112
*/
12-
const setEntry = (fn, servicePath) =>
13+
const setEntry = (fn, servicePath, useTypeScript) =>
1314
R.assoc(
1415
'entry',
1516
R.objOf(
16-
service.fnPath(fn),
17-
path.join(servicePath, service.fnPath(fn))
17+
service.fnPath('.js')(fn),
18+
path.join(servicePath, service.fnPath(useTypeScript ? '.ts' : '.js')(fn))
1819
)
1920
);
2021

@@ -40,13 +41,14 @@ const setOutput = (defaultOutput, outputPath) =>
4041
* @param {string} servicePath Serverless service path
4142
* @param {object} defaultOutput Webpack default output object
4243
* @param {string} folder Webpack output folder
44+
* @param {boolean} useTypeScript Use .ts extension
4345
* @returns {array} Array of webpack configurations
4446
*/
45-
const createConfigs = (fns, config, servicePath, defaultOutput, folder) =>
47+
const createConfigs = (fns, config, servicePath, defaultOutput, folder, useTypeScript) =>
4648
R.map(
4749
fn =>
4850
R.pipe(
49-
setEntry(fn, servicePath),
51+
setEntry(fn, servicePath, useTypeScript),
5052
setOutput(defaultOutput, path.join(servicePath, folder))
5153
)(config),
5254
R.values(fns)

0 commit comments

Comments
 (0)