1. npm install --save-dev typescript ts-loader
    1. webpack-demo
    2. |- package.json
    3. + |- tsconfig.json
    4. |- webpack.config.js
    5. |- /dist
    6. |- bundle.js
    7. |- index.html
    8. |- /src
    9. |- index.js
    10. + |- index.ts
    11. |- /node_modules
    1. // tsconfig.json
    2. {
    3. "compilerOptions": {
    4. "outDir": "./dist/",
    5. "sourceMap": true,
    6. "noImplicitAny": true,
    7. "module": "es6",
    8. "target": "es5",
    9. "jsx": "react",
    10. "allowJs": true
    11. }
    12. }
    1. const path = require('path');
    2. module.exports = {
    3. entry: './src/index.ts',
    4. + devtool: 'inline-source-map',
    5. module: {
    6. rules: [
    7. {
    8. test: /\.tsx?$/,
    9. use: 'ts-loader',
    10. exclude: /node_modules/
    11. }
    12. ]
    13. },
    14. resolve: {
    15. extensions: [ '.tsx', '.ts', '.js' ]
    16. },
    17. output: {
    18. filename: 'bundle.js',
    19. path: path.resolve(__dirname, 'dist')
    20. }
    21. };