Skip to content

Commit b6678d1

Browse files
committed
TypeScript support
1 parent b7b4f4a commit b6678d1

File tree

4 files changed

+20
-15
lines changed

4 files changed

+20
-15
lines changed

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
@@ -61,7 +61,8 @@ class ServerlessPluginWebpack {
6161
webpackConfig,
6262
this.originalServicePath,
6363
webpackDefaultOutput,
64-
webpackFolder
64+
webpackFolder,
65+
this.custom.typescript,
6566
));
6667
}
6768

@@ -85,7 +86,7 @@ class ServerlessPluginWebpack {
8586
}
8687

8788
clean() {
88-
return fs.remove(path.join(this.originalServicePath, webpackFolder));
89+
// return fs.remove(path.join(this.originalServicePath, webpackFolder));
8990
}
9091
}
9192

src/lib/service.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,16 @@ 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

17-
const setFnsPackage = R.map(R.pipe(
18-
R.when(R.prop('package'), R.over(R.lensProp('package'), makePackageRelative)),
19-
R.converge(
20-
R.over(R.lensPath(['package', 'include'])),
21-
[R.compose(R.append, fnPath), R.identity]
22-
)
23-
));
17+
const setFnsPackage = R.map(
18+
R.pipe(
19+
R.when(R.prop('package'), R.over(R.lensProp('package'), makePackageRelative)),
20+
R.converge(
21+
R.over(R.lensPath(['package', 'include'])),
22+
[R.compose(R.append, fnPath('.js')), R.identity]
23+
)
24+
));
2425

2526
const setFnsArtifacts = (serverlessPath, fns) => R.map(
2627
R.over(

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)