Skip to content

Commit 6011d92

Browse files
authored
[Webpack] Update webpack config to allow typescript files. (#1550)
1 parent 8d2c0f8 commit 6011d92

File tree

6 files changed

+30
-26
lines changed

6 files changed

+30
-26
lines changed

cfg/base.js

+1-7
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,6 @@ module.exports = {
2222
entry: ['./src/entry'],
2323
module: {
2424
rules: [
25-
{
26-
enforce: 'pre',
27-
include: path.join(__dirname, 'src'),
28-
test: /\.(js|jsx)$/,
29-
use: 'eslint-loader',
30-
},
3125
{
3226
test: /\.css$/,
3327
use: ['style-loader', 'css-loader'],
@@ -101,6 +95,6 @@ module.exports = {
10195
store: srcPath + '/store/',
10296
styles: srcPath + '/styles/',
10397
},
104-
extensions: ['.js', '.jsx', '_pb.js'],
98+
extensions: ['.js', '.jsx', '_pb.js', '.ts', '.tsx', '_pb.d.ts'],
10599
},
106100
}

cfg/dev.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,17 @@ config.module.rules.push({
4444
include: [
4545
path.join(__dirname, '/../src'),
4646
],
47-
test: /\.(js|jsx)$/,
47+
test: /\.[jt]sx?$/,
4848
use: {
4949
loader: 'babel-loader',
5050
options: {
5151
plugins: [
5252
'react-hot-loader/babel',
5353
'@babel/plugin-syntax-dynamic-import',
5454
['@babel/plugin-proposal-class-properties', {loose: false}],
55+
['@babel/plugin-proposal-optional-chaining', {loose: false}],
5556
],
56-
presets: [['@babel/env', {modules: false}], '@babel/react'],
57+
presets: [['@babel/env', {modules: false}], '@babel/react', '@babel/typescript'],
5758
},
5859
},
5960
})

cfg/dist.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,15 @@ config.module.rules.push({
5353
include: [
5454
path.join(__dirname, '/../src'),
5555
],
56-
test: /\.(js|jsx)$/,
56+
test: /\.[jt]sx?$/,
5757
use: 'babel-loader',
58+
options: {
59+
plugins: [
60+
['@babel/plugin-proposal-class-properties', {loose: false}],
61+
['@babel/plugin-proposal-optional-chaining', {loose: false}],
62+
],
63+
presets: [['@babel/env', {modules: false}], '@babel/react', '@babel/typescript'],
64+
}
5865
})
5966

6067
module.exports = config

cfg/test.js

+16-14
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
var path = require('path')
22
var srcPath = path.join(__dirname, '/../src/')
3+
var baseConfig = require('./base')
34

45
module.exports = {
56
devtool: 'eval',
@@ -13,22 +14,23 @@ module.exports = {
1314
},
1415
{
1516
include: [
16-
path.join(__dirname, '/../src'),
17-
path.join(__dirname, '/../test'),
17+
path.join(__dirname, '../src'),
18+
path.join(__dirname, '../test'),
1819
],
19-
test: /\.(js|jsx)$/,
20-
use: 'babel-loader',
20+
test: /\.[jt]sx?$/,
21+
use: {
22+
loader: 'babel-loader',
23+
options: {
24+
plugins: [
25+
'@babel/plugin-syntax-dynamic-import',
26+
['@babel/plugin-proposal-class-properties', {loose: false}],
27+
['@babel/plugin-proposal-optional-chaining', {loose: false}],
28+
],
29+
presets: [['@babel/env', {modules: false}], '@babel/react', '@babel/typescript'],
30+
},
31+
},
2132
},
2233
],
2334
},
24-
resolve: {
25-
alias: {
26-
components: srcPath + 'components/',
27-
config: srcPath + 'config/' + process.env.REACT_WEBPACK_ENV,
28-
images: srcPath + 'images/',
29-
store: srcPath + 'store/',
30-
styles: srcPath + 'styles/',
31-
},
32-
extensions: ['.js', '.jsx', '_pb.js'],
33-
},
35+
resolve: baseConfig.resolve,
3436
}

server.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*eslint no-console:0 */
1+
/* eslint no-console:0 */
22
var webpack = require('webpack')
33
var WebpackDevServer = require('webpack-dev-server')
44
var config = require('./webpack.config')

webpack.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ var args = require('minimist')(process.argv.slice(2))
88
var allowedEnvs = ['dev', 'dist', 'test']
99

1010
// Set the correct environment.
11-
if(args._.length > 0 && args._.indexOf('start') !== -1) {
11+
if (args._.length > 0 && args._.indexOf('start') !== -1) {
1212
process.env.REACT_WEBPACK_ENV = 'test'
1313
} else if (!process.env.REACT_WEBPACK_ENV) {
1414
process.env.REACT_WEBPACK_ENV = 'dev'

0 commit comments

Comments
 (0)