webpack 问题归纳

afcfzf 2021年02月18日 177次浏览
  1. webpack.config如果是ts,那么安装ts-node、tsconfig-paths就可以了,无需按照webpack-cli安装依赖
  2. tsconfig.json如果有自定义类型,需要把路径放到inclides里面
"include": [
     "./typings/**/*.d.ts",
     "src/**/*.ts"
]
  1. 可选链错误
"scripts": {
    "preinstall": "npx npm-force-resolutions",
},
"resolutions": {
    "acorn": "8.0.1"
},
  1. eslint globals
globals: 
    Units: true
    TypeUnits: true
    DialogModes: true
    DescValueType: true
    pixelsToAppUnits: true
    ActionDescriptor: true
    ActionReference: true
    charIDToTypeID: true
    ActionList: true
    ActionReference: true
  1. prettier operator-linebreak问题: 换个版本
npm i npm install --save-dev prettier@npm:@btmills/prettier -D
  1. Could not find a declaration file for module
declare module 'xxx'; 

tsconfig.json
 - "noImplicitAny": true // 该参数问题
  1. 编译es5
{
                test: /\.tsx?$/,
                use: [
                    {
                        loader: 'babel-loader',
                        options: {
                            presets: [
                                [
                                    '@babel/preset-env',
                                    {
                                        modules: false,
                                        loose: true,
                                        targets: {
                                            browsers: [
                                                '> 1%',
                                                'last 2 versions',
                                                'ie <= 9'
                                            ]
                                        }
                                    }
                                ]
                            ],
                            plugins: [
                                [
                                    '@babel/plugin-proposal-class-properties',
                                    {
                                        loose: false
                                    }
                                ],
                                [
                                    'import',
                                    {
                                        libraryName: '@byte-design/icons',
                                        libraryDirectory: 'icons',
                                        camel2DashComponentName: false
                                    }
                                ],
                                '@babel/plugin-transform-object-assign'
                            ]
                        }
                    },
                    {
                        loader: 'ts-loader',
                        options: {
                            configFile: resolve('tsconfig.json'),
                            compilerOptions: {
                                module: 'EsNext',
                                target: 'es5'
                            }
                        }
                    }
                ],
                include: [resolve('src')],
                exclude: [resolve('node_modules')]
            }