-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #127 from KidkArolis/add-ts-support
Add TypeScript support
- Loading branch information
Showing
17 changed files
with
3,894 additions
and
1,135 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
const requireRelative = require('require-relative') | ||
|
||
module.exports = (config, options) => { | ||
if (options.react) { | ||
const reactPath = getReactPath(options.dir) | ||
if (reactPath) { | ||
config.resolve.alias.react = reactPath | ||
} | ||
const reactDOMPath = getReactDOMPath(options.dir) | ||
if (reactDOMPath) { | ||
config.resolve.alias['react-dom'] = reactDOMPath | ||
} | ||
|
||
config.module.rules[0].oneOf.forEach((rule) => { | ||
if (rule.use) { | ||
rule.use.forEach((loader) => { | ||
if (loader.loader === require.resolve('swc-loader') || loader.loader === 'builtin:swc-loader') { | ||
loader.options.jsc.transform.react = { | ||
runtime: 'automatic', | ||
development: !options.production, | ||
refresh: !options.production && options.hot | ||
} | ||
} | ||
}) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
function getReactPath(dir) { | ||
try { | ||
return requireRelative.resolve('react', dir).replace(/\/index.js$/, '') | ||
} catch (err) { | ||
if (err.code !== 'MODULE_NOT_FOUND') { | ||
throw err | ||
} | ||
} | ||
return null | ||
} | ||
|
||
function getReactDOMPath(dir) { | ||
try { | ||
return requireRelative.resolve('react-dom', dir).replace(/\/index.js$/, '') | ||
} catch (err) { | ||
if (err.code !== 'MODULE_NOT_FOUND') { | ||
throw err | ||
} | ||
} | ||
return null | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
const browsers = require('./browsers') | ||
|
||
module.exports = (config, options) => { | ||
config.module.rules[0].oneOf.push({ | ||
test: /\.(ts|tsx)$/, | ||
exclude: /(node_modules)/, | ||
use: [ | ||
{ | ||
loader: 'builtin:swc-loader', | ||
options: { | ||
env: { | ||
targets: browsers.query(options), | ||
coreJs: '3.40', | ||
mode: 'usage' | ||
}, | ||
jsc: { | ||
parser: { | ||
syntax: 'typescript', | ||
exportDefaultFrom: true, | ||
jsx: true | ||
}, | ||
externalHelpers: true, | ||
transform: {} | ||
}, | ||
isModule: 'unknown' | ||
} | ||
} | ||
] | ||
}) | ||
} |
Oops, something went wrong.