Skip to content

Commit a8d4dad

Browse files
committed
feat(typescript) : add typewiz for migration to ts
1 parent 90e9a61 commit a8d4dad

File tree

2 files changed

+113
-93
lines changed

2 files changed

+113
-93
lines changed

React_Full_Project/package.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
"license": "MIT",
99
"private": true,
1010
"devDependencies": {
11+
"@types/classnames": "^2.2.3",
12+
"@types/react": "^16.1.0",
13+
"@types/react-router-dom": "^4.2.6",
14+
"@types/reactstrap": "^5.0.20",
1115
"babel-core": "6.26.0",
1216
"babel-loader": "7.1.2",
1317
"babel-plugin-transform-object-rest-spread": "6.26.0",
@@ -25,12 +29,15 @@
2529
"sass-loader": "6.0.6",
2630
"source-list-map": "2.0.0",
2731
"style-loader": "0.20.1",
32+
"typewiz": "^0.7.0",
2833
"uglify-js": "3.3.9",
2934
"url-loader": "0.6.2",
35+
"walk-sync": "^0.3.2",
3036
"webpack": "3.10.0",
3137
"webpack-dev-server": "2.11.1"
3238
},
3339
"dependencies": {
40+
"awesome-typescript-loader": "^4.0.1",
3441
"bootstrap": "4.0.0",
3542
"chart.js": "2.7.1",
3643
"flag-icon-css": "2.9.0",
@@ -42,7 +49,8 @@
4249
"react-router-dom": "4.2.2",
4350
"react-transition-group": "2.2.1",
4451
"reactstrap": "5.0.0-beta",
45-
"simple-line-icons": "2.4.1"
52+
"simple-line-icons": "2.4.1",
53+
"typewiz-webpack": "^0.3.3"
4654
},
4755
"scripts": {
4856
"dev": "webpack -d --progress --watch --profile --json > compilation-stats.json --env.dev",

React_Full_Project/webpack.config.js

Lines changed: 104 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ const path = require('path');
33
const ExtractTextPlugin = require('extract-text-webpack-plugin');
44
const HtmlWebpackPlugin = require('html-webpack-plugin');
55
const CopyWebpackPlugin = require('copy-webpack-plugin');
6+
const {CheckerPlugin} = require('awesome-typescript-loader');
7+
const {TypewizPlugin, typewizCollectorMiddleware} = require('typewiz-webpack');
68

79
const extractCSS = new ExtractTextPlugin('[name].fonts.css');
810
const extractSCSS = new ExtractTextPlugin('[name].styles.css');
@@ -14,99 +16,109 @@ console.log('BUILD_DIR', BUILD_DIR);
1416
console.log('SRC_DIR', SRC_DIR);
1517

1618
module.exports = (env = {}) => {
17-
return {
18-
entry: {
19-
index: [SRC_DIR + '/index.js']
20-
},
21-
output: {
22-
path: BUILD_DIR,
23-
filename: '[name].bundle.js'
24-
},
25-
// watch: true,
26-
devtool: env.prod ? 'source-map' : 'cheap-module-eval-source-map',
27-
devServer: {
28-
contentBase: BUILD_DIR,
29-
// port: 9001,
30-
compress: true,
31-
hot: true,
32-
open: true
33-
},
34-
module: {
35-
rules: [
36-
{
37-
test: /\.(js|jsx)$/,
38-
exclude: /node_modules/,
39-
use: {
40-
loader: 'babel-loader',
41-
options: {
42-
cacheDirectory: true,
43-
presets: ['react', 'env']
44-
}
45-
}
19+
return {
20+
entry: {
21+
index: [SRC_DIR + '/index.js']
4622
},
47-
{
48-
test: /\.html$/,
49-
loader: 'html-loader'
23+
output: {
24+
path: BUILD_DIR,
25+
filename: '[name].bundle.js'
5026
},
51-
{
52-
test: /\.(scss)$/,
53-
use: ['css-hot-loader'].concat(extractSCSS.extract({
54-
fallback: 'style-loader',
55-
use: [
56-
{
57-
loader: 'css-loader',
58-
options: {alias: {'../img': '../public/img'}}
59-
},
60-
{
61-
loader: 'sass-loader'
62-
}
63-
]
64-
}))
27+
// watch: true,
28+
devtool: env.prod ? 'source-map' : 'cheap-module-eval-source-map',
29+
devServer: {
30+
before: function (app) {
31+
typewizCollectorMiddleware(app, 'collected-types.json');
32+
},
33+
contentBase: BUILD_DIR,
34+
// port: 9001,
35+
compress: true,
36+
hot: true,
37+
open: true
6538
},
66-
{
67-
test: /\.css$/,
68-
use: extractCSS.extract({
69-
fallback: 'style-loader',
70-
use: 'css-loader'
71-
})
39+
module: {
40+
rules: [
41+
{
42+
test: /\.tsx?$/,
43+
loaders: ['awesome-typescript-loader', 'typewiz-webpack']
44+
},
45+
{
46+
test: /\.(js|jsx)$/,
47+
exclude: /node_modules/,
48+
use: {
49+
loader: 'babel-loader',
50+
options: {
51+
cacheDirectory: true,
52+
presets: ['react', 'env']
53+
}
54+
}
55+
},
56+
{
57+
test: /\.html$/,
58+
loader: 'html-loader'
59+
},
60+
{
61+
test: /\.(scss)$/,
62+
use: ['css-hot-loader'].concat(extractSCSS.extract({
63+
fallback: 'style-loader',
64+
use: [
65+
{
66+
loader: 'css-loader',
67+
options: {alias: {'../img': '../public/img'}}
68+
},
69+
{
70+
loader: 'sass-loader'
71+
}
72+
]
73+
}))
74+
},
75+
{
76+
test: /\.css$/,
77+
use: extractCSS.extract({
78+
fallback: 'style-loader',
79+
use: 'css-loader'
80+
})
81+
},
82+
{
83+
test: /\.(png|jpg|jpeg|gif|ico)$/,
84+
use: [
85+
{
86+
// loader: 'url-loader'
87+
loader: 'file-loader',
88+
options: {
89+
name: './img/[name].[hash].[ext]'
90+
}
91+
}
92+
]
93+
},
94+
{
95+
test: /\.(woff(2)?|ttf|eot|svg)(\?v=\d+\.\d+\.\d+)?$/,
96+
loader: 'file-loader',
97+
options: {
98+
name: './fonts/[name].[hash].[ext]'
99+
}
100+
}]
72101
},
73-
{
74-
test: /\.(png|jpg|jpeg|gif|ico)$/,
75-
use: [
76-
{
77-
// loader: 'url-loader'
78-
loader: 'file-loader',
79-
options: {
80-
name: './img/[name].[hash].[ext]'
81-
}
82-
}
83-
]
84-
},
85-
{
86-
test: /\.(woff(2)?|ttf|eot|svg)(\?v=\d+\.\d+\.\d+)?$/,
87-
loader: 'file-loader',
88-
options: {
89-
name: './fonts/[name].[hash].[ext]'
90-
}
91-
}]
92-
},
93-
plugins: [
94-
new webpack.HotModuleReplacementPlugin(),
95-
new webpack.optimize.UglifyJsPlugin({sourceMap: true}),
96-
new webpack.NamedModulesPlugin(),
97-
extractCSS,
98-
extractSCSS,
99-
new HtmlWebpackPlugin(
100-
{
101-
inject: true,
102-
template: './public/index.html'
103-
}
104-
),
105-
new CopyWebpackPlugin([
106-
{from: './public/img', to: 'img'}
107-
],
108-
{copyUnmodified: false}
109-
)
110-
]
111-
}
112-
};
102+
plugins: [
103+
new webpack.HotModuleReplacementPlugin(),
104+
new webpack.optimize.UglifyJsPlugin({sourceMap: true}),
105+
new webpack.NamedModulesPlugin(),
106+
new CheckerPlugin(),
107+
new TypewizPlugin(),
108+
109+
extractCSS,
110+
extractSCSS,
111+
new HtmlWebpackPlugin(
112+
{
113+
inject: true,
114+
template: './public/index.html'
115+
}
116+
),
117+
new CopyWebpackPlugin([
118+
{from: './public/img', to: 'img'}
119+
],
120+
{copyUnmodified: false}
121+
),
122+
]
123+
}
124+
};

0 commit comments

Comments
 (0)