Skip to content

Commit

Permalink
feat: support typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
vision-git-robot committed May 21, 2019
1 parent 324811f commit b66fde1
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
1 change: 1 addition & 0 deletions packages/a8k/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@
"svg-inline-loader": "^0.8.0",
"terser": "^4.0.0",
"terser-webpack-plugin": "^1.2.4",
"ts-loader": "^6.0.1",
"url": "^0.11.0",
"webpack": "^4.31.0",
"webpack-bundle-analyzer": "^3.3.2",
Expand Down
11 changes: 7 additions & 4 deletions packages/a8k/src/plugins/config-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ exports.apply = context => {
// TODO:项目里面有使用到
// config.module.set('wrappedContextRecursive', false);

require('../webpack/rules/ts')(config, context, options);
require('../webpack/rules/js')(config, context, options);
require('../webpack/rules/css')(config, context, options, filenames.css);
require('../webpack/rules/fonts')(config, context, options, filenames.font);
Expand All @@ -86,10 +87,12 @@ exports.apply = context => {

if (analyzer) {
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
config.plugin('bundle-analyzer-plugin').use(BundleAnalyzerPlugin, [{
analyzerMode: 'static',
reportFilename: `a8k_report_${type}.html`,
}]);
config.plugin('bundle-analyzer-plugin').use(BundleAnalyzerPlugin, [
{
analyzerMode: 'static',
reportFilename: `a8k_report_${type}.html`,
},
]);
}
});
};
Expand Down
7 changes: 7 additions & 0 deletions packages/a8k/src/plugins/config-html.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,17 @@ const getPages = context => {
return false;
}
let filepath = path.join(pagesDir, item, 'index.js');
const filePathTs = path.join(pagesDir, item, 'index.ts');

if (!fs.existsSync(filepath)) {
filepath = `${filepath}x`; // jsx
}
if (!fs.existsSync(filepath)) {
filepath = filePathTs;
}
if (!fs.existsSync(filepath)) {
filepath = `${filepath}x`; // tsx
}
if (!fs.existsSync(filepath)) {
return false;
}
Expand Down
7 changes: 7 additions & 0 deletions packages/a8k/src/webpack/rules/ts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = config => {
config.module
.rule('ts')
.test(/\.tsx?$/)
.use('ts-loader')
.loader('ts-loader');
};

0 comments on commit b66fde1

Please sign in to comment.