Skip to content

Commit

Permalink
feat(build): add typescript support
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanPiercey committed Oct 18, 2024
1 parent e0f0f47 commit d601b8b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
1 change: 1 addition & 0 deletions packages/build/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"dependencies": {
"@babel/core": "^7.17.5",
"@babel/preset-env": "^7.16.11",
"@babel/preset-typescript": "^7.17.12",
"@babel/runtime": "^7.17.2",
"@marko/babel-utils": "^5.19.1",
"@marko/compiler": "^5.19.1",
Expand Down
20 changes: 13 additions & 7 deletions packages/build/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,13 @@ const configBuilder = (exports.configBuilder = ({
compact: false,
babelrc: false,
configFile: false,
browserslistConfigFile: false
browserslistConfigFile: false,
overrides: [
{
test: /\.[cm]?ts$/,
presets: [require.resolve("@babel/preset-typescript")]
}
]
});

const babelLoader = targets => ({
Expand Down Expand Up @@ -156,7 +162,7 @@ const configBuilder = (exports.configBuilder = ({

return [
{
test: /\.[cm]?js$/,
test: /\.[cm]?[jt]s$/,
exclude: !production || isServer ? /node_modules/ : undefined,
use: [babelLoader(targets)]
},
Expand Down Expand Up @@ -212,7 +218,7 @@ const configBuilder = (exports.configBuilder = ({
{
test: file =>
file &&
!/\.([cm]?js|json|css|less|s[ac]ss|styl|wasm|marko)$/.test(file),
!/\.([cm]?[jt]s|json|css|less|s[ac]ss|styl|wasm|marko)$/.test(file),
use: [
{
loader: require.resolve("file-loader"),
Expand Down Expand Up @@ -256,7 +262,7 @@ const configBuilder = (exports.configBuilder = ({
context: CONTEXT,
resolve: {
alias: sharedAliases(options),
extensions: [".wasm", ".mjs", ".js", ".json", ".marko"]
extensions: [".wasm", ".mjs", ".js", ".json", ".ts", ".mts", ".marko"]
},
cache: { type: "filesystem" },
module: { rules: sharedRules(options) }
Expand Down Expand Up @@ -421,9 +427,9 @@ function loadBrowsersLists(entry, production) {
const customBrowsersList = browserslist.findConfig(entry);

if (customBrowsersList) {
const customBrowserEnvs = Object.entries(
customBrowsersList
).map(([env, targets]) => ({ env, targets }));
const customBrowserEnvs = Object.entries(customBrowsersList).map(
([env, targets]) => ({ env, targets })
);
const activeBrowserEnvs = customBrowserEnvs.filter(
({ env, targets }) =>
targets.length && (production ? env !== "dev" : env === "dev")
Expand Down

0 comments on commit d601b8b

Please sign in to comment.