Skip to content

Commit 348a60a

Browse files
committed
feat: add TS support
1 parent a155da8 commit 348a60a

File tree

3 files changed

+133
-10
lines changed

3 files changed

+133
-10
lines changed

package-lock.json

+121-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
"postcss-loader": "4.3.0",
5353
"postcss-simple-vars": "^5.0.1",
5454
"style-loader": "4.0.0",
55+
"ts-loader": "^9.5.1",
5556
"url-loader": "4.1.1",
5657
"webpack": "^5.90.3"
5758
}

src/index.cjs

+11-3
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class ScratchWebpackConfigBuilder {
3737
* @param {string|URL} [options.srcPath] The absolute path to the source files. Defaults to `src` under `rootPath`.
3838
* @param {boolean} [options.shouldSplitChunks] Whether to enable spliting code to chunks.
3939
*/
40-
constructor ({ distPath, enableReact, libraryName, rootPath, srcPath, shouldSplitChunks }) {
40+
constructor ({ distPath, enableReact, enableTs, libraryName, rootPath, srcPath, shouldSplitChunks }) {
4141
const isProduction = process.env.NODE_ENV === 'production';
4242
const mode = isProduction ? 'production' : 'development';
4343

@@ -90,6 +90,7 @@ class ScratchWebpackConfigBuilder {
9090
'.jsx'
9191
] : []
9292
),
93+
...(enableTs ? ['.ts', '.tsx'] : []),
9394
// webpack supports '...' to include defaults, but eslint does not
9495
'.js',
9596
'.json'
@@ -98,7 +99,9 @@ class ScratchWebpackConfigBuilder {
9899
module: {
99100
rules: [
100101
{
101-
test: enableReact ? /\.[cm]?jsx?$/ : /\.[cm]?js$/,
102+
test: enableReact ?
103+
(enableTs ? /\.[cm]?[jt]sx?$/ : /\.[cm]?jsx?$/) :
104+
(enableTs ? /\.[cm]?[jt]s$/ : /\.[cm]?js$/),
102105
loader: 'babel-loader',
103106
exclude: [
104107
{
@@ -196,7 +199,12 @@ class ScratchWebpackConfigBuilder {
196199
]
197200
}
198201
] : []
199-
)
202+
),
203+
...(enableTs ? [{
204+
test: enableReact ? /\.[cm]?[jt]sx?$/ : /\.[cm]?[jt]s$/,
205+
loader: 'ts-loader',
206+
exclude: [/node_modules/]
207+
}] : []),
200208
],
201209

202210
},

0 commit comments

Comments
 (0)