尝试了下将es6直接换成typescript,但是会提示找不到@types react文件,虽然和课程的技术栈不太一样,但还是希望老师能帮我看看
tsconfig
{ "compilerOptions": { "outDir": "./dist/", "sourceMap": true, "noImplicitAny": true, "module": "commonjs", "target": "es5", "jsx": "react"
}, "include": [ "./src/**/*"
]
}
webpack.production.config.js
var path = require('path');var pkg = require('./package.json');var webpack = require('webpack');var HtmlWebpackPlugin = require('html-webpack-plugin');module.exports = {
entry: {
app: __dirname + '/src/index.tsx',
vendor: Object.keys(pkg.dependencies)
},
output: {
filename: "./js/[name].[hash].js",
path: __dirname + '/build'
},
resolve: {
extensions: [ '.ts', '.tsx', '.js', '.web', '.webpack.js', '.json'
]
}, module: {
rules: [
{test: /\.tsx?$/, loader: 'awesome-typescript-loader'},
{enforce: 'pre', test: /\.js$/, loader: 'source-map-loader'}
]
},
plugins: [ new HtmlWebpackPlugin({
template: path.resolve(__dirname, 'index.html')
}), new webpack.HotModuleReplacementPlugin(), new webpack.DefinePlugin({ 'process.env': { 'NODE_ENV': JSON.stringify('production')
}
}), new webpack.optimize.OccurrenceOrderPlugin(), new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false
}
}), new webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
filename: './js/[name].[hash].js'
})
],
devServer: {
contentBase: './',
historyApiFallback: true,
inline: true,
hot: true
}
};
package.json
{ "name": "webpack-test3", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1", "server": "webpack-dev-server --open", "build":"webpack --progress --profile --config webpack.production.config.js"
}, "author": "", "license": "ISC", "devDependencies": { "awesome-typescript-loader": "^3.2.3", "html-webpack-plugin": "^2.30.1", "source-map-loader": "^0.2.1", "typescript": "^2.4.2", "webpack": "^3.5.5", "webpack-dev-server": "^2.7.1"
}, "dependencies": { "@types/react": "^16.0.2", "@types/react-dom": "^15.5.3", "react": "^15.6.1", "react-dom": "^15.6.1"
}
}
报错信息是
ERROR in multi @types/react @types/react-doom react react-dom
Module not found: Error: Can't resolve '@types/react' in ‘E:\webpack\webpack-test'