Skip to content

Commit 320b0e8

Browse files
committed
fix: allow importing code transform from cjs
1 parent 1bb1c77 commit 320b0e8

File tree

5 files changed

+532
-7
lines changed

5 files changed

+532
-7
lines changed

examples/with-express/package.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
"type": "module",
66
"scripts": {
77
"build": "rollup -c",
8-
"build:esbuild": "node esbuild.build.js"
8+
"build:esbuild": "node esbuild.build.js",
9+
"build:webpack": "webpack"
910
},
1011
"dependencies": {
1112
"@rollup/plugin-commonjs": "^25.0.0",
@@ -17,6 +18,11 @@
1718
"useflytrap": "workspace:*"
1819
},
1920
"devDependencies": {
20-
"@types/express": "^4.17.17"
21+
"@types/express": "^4.17.17",
22+
"@types/webpack": "^5.28.1",
23+
"ts-loader": "^9.4.4",
24+
"webpack": "^5.88.0",
25+
"webpack-cli": "^5.1.4",
26+
"webpack-node-externals": "^3.0.0"
2127
}
2228
}

examples/with-express/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ app.put('/todos/:id', (req: Request, res: Response) => {
3232

3333
const foundTodo = todos.find((todo) => todo.id === id)
3434

35-
// @ts-expect-error
35+
// @ts-ignore
3636
foundTodo.completed = req.body.completed
37-
// @ts-expect-error
37+
// @ts-ignore
3838
foundTodo.title = req.body.title
3939

4040
res.json(foundTodo)
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// @ts-check
2+
const path = require('path');
3+
const nodeExternals = require('webpack-node-externals');
4+
const { FlytrapTransformPlugin } = require('useflytrap/transform');
5+
6+
/** @type { import('webpack').Configuration } */
7+
module.exports = {
8+
target: 'node',
9+
mode: 'production',
10+
externals: [nodeExternals()],
11+
entry: {
12+
app: './src/index.ts'
13+
},
14+
output: {
15+
path: path.resolve(__dirname, 'dist'),
16+
filename: '[name].cjs'
17+
},
18+
resolve: {
19+
extensions: ['.ts', '.js'],
20+
},
21+
module: {
22+
rules: [
23+
{
24+
test: /\.ts$/,
25+
use: [
26+
'ts-loader',
27+
],
28+
},
29+
],
30+
},
31+
plugins: [
32+
FlytrapTransformPlugin.webpack()
33+
]
34+
};

0 commit comments

Comments
 (0)