start react+webpack+typescript

webpack加载css文件

Module parse failed: Unexpected token (1:0)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file.

css-loader-error.png

参考链接:
https://stackoverflow.com/questions/42530582/css-module-parse-failed

css-module-parse.png

webpack无法正确加载css文件,需要在webpack.config.ts中加入css-loader

// 首先要安装style-loader css-loader
npm install --save-dev style-loader css-loader

修改配置

 module: {
    rules: [
      {
         /** 其它loader  **/
      },
      {
        test: /\.css$/,
        exclude: /node_modules/,
        use: ['style-loader', 'css-loader'],
      },
    ],
  },

Eslint忽略css文件

[unknown]: Parsing error: ';' expected.

css-parse-error.png

https://stackoverflow.com/questions/63596271/webpack-with-css-loader-parsing-error-expected

修改webpack.config.ts,配置eslint不检查css文件

plugins: [
    new ForkTsCheckerWebpackPlugin({
      async: false,
      eslint: {
        files: ['./src/**/*.js', './src/**/*.ts', './src/**/*.tsx'],
      },
    }),
  ],

你可能感兴趣的:(start react+webpack+typescript)