[ts] Plug-ins and configurations that must be installed and configured for vue projects using ts (generally, scaffolding will help you when building vue, but you still need to know what these codes are in the project)

使用ts的项目,是需要安装ts-loader来处理.ts文件的。

例如babel-loader是用于处理js文件,而ts就是ts-loader

  1. First make sure whether the project has webpack and typescript installed
npm install webpack --save-dev
npm install typescript --save-dev
  1. Install ts-loader, a Webpack loader for handling TypeScript files.
npm install ts-loader --save-dev
  1. In the Webpack configuration file, add processing rules for .ts files. Add the following configuration to the module.rules array:
module.exports = {
    
    
  // ...其他配置项
  module: {
    
    
    rules: [
      // 处理.ts文件的loader规则,排除了node_modules目录
      {
    
    
        test: /\.ts$/,
        loader: 'ts-loader',
        exclude: /node_modules/,		
      },
    ],
  },
};

Guess you like

Origin blog.csdn.net/bbt953/article/details/132378849