-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: Adding Typescript block (#21)
- Loading branch information
Showing
5 changed files
with
2,693 additions
and
1,348 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
const ForkTsCheckerWebpackPlugin = require("fork-ts-checker-webpack-plugin"); | ||
const { cpus } = require("os"); | ||
|
||
const { ensureConfig, safeMerge, deduplicate } = require("../utils"); | ||
|
||
module.exports = blockConfig => (processEnv, argv) => argConfig => { | ||
const isDev = processEnv.NODE_ENV === "development"; | ||
const isHotReload = processEnv.HOT_RELOAD === "true"; | ||
|
||
const defaultConf = { | ||
useCache: isDev, | ||
mode: processEnv.NODE_ENV, | ||
hot: isHotReload, | ||
test: /\.(ts|tsx)$/, | ||
exclude: /node_modules/, | ||
extensions: [".ts", ".tsx"] | ||
}; | ||
|
||
const mergedConf = safeMerge(defaultConf, blockConfig); | ||
const config = ensureConfig(argConfig); | ||
|
||
config.module.rules.push({ | ||
test: mergedConf.test, | ||
exclude: mergedConf.exclude, | ||
use: [ | ||
{ | ||
loader: "thread-loader", | ||
options: { | ||
// Let's leave 1 cpu free, for async type checking | ||
workers: Math.max(cpus().length - (mergedConf.hot ? 1 : 0), 1) | ||
} | ||
}, | ||
mergedConf.useCache && { | ||
loader: "cache-loader" | ||
}, | ||
{ | ||
loader: "babel-loader", | ||
options: { | ||
cacheDirectory: false, | ||
presets: [ | ||
[ | ||
"@thc/babel-preset-react", | ||
{ | ||
mode: mergedConf.mode, | ||
hot: mergedConf.hot | ||
} | ||
] | ||
], | ||
babelrc: false | ||
} | ||
}, | ||
{ | ||
loader: "ts-loader", | ||
options: { | ||
transpileOnly: true // Leave type checking to plugin | ||
} | ||
} | ||
].filter(Boolean) | ||
}); | ||
|
||
config.plugins.push( | ||
new ForkTsCheckerWebpackPlugin({ | ||
tslint: true, | ||
async: mergedConf.hot | ||
}) | ||
); | ||
|
||
config.resolve.extensions = deduplicate(config.resolve.extensions, mergedConf.extensions); | ||
|
||
return config; | ||
}; |
Oops, something went wrong.