我使用过babel loader和typescript react,cssModules和eslint (带有更漂亮的)。我已经和webpack一起创建了commonjs库,但是当我开始使用这个库的示例项目时,我得到了像这样的错误。
我没有任何想法来解决这个问题。耽误您时间,实在对不起。
我的WEBPACK配置:
const path = require('path');
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const Dotenv = require('dotenv-webpack');
module.exports = {
mode: 'production',
entry: ['react-hot-loader', './index.tsx'],
devtool: 'eval-source-map',
output: {
path: path.resolve('dist'),
filename: 'index.js',
library: {
name: 'proba-react-library',
type: 'commonjs'
}
},
context: path.resolve(__dirname, 'src'),
module: {
rules: [
{
test: /\.tsx?$/,
exclude: /node_modules/,
use: [
{
loader: 'babel-loader',
options: {
cacheDirectory: true,
babelrc: false,
presets: [
[
'@babel/preset-env',
{
targets: { browsers: 'last 2 versions' },
modules: 'commonjs'
} // or whatever your project requires
],
[
'@babel/typescript',
{
configFile: path.resolve(__dirname, 'tsconfig.json'),
isTSX: true,
allExtensions: true
}
],
[
'@babel/preset-react',
{
flow: false,
typescript: true
}
]
],
plugins: [
// plugin-proposal-decorators is only needed if you're using experimental decorators in TypeScript
['@babel/plugin-proposal-decorators', { legacy: true }],
['@babel/plugin-proposal-class-properties'],
'react-hot-loader/babel',
'@babel/plugin-transform-runtime',
'@babel/plugin-transform-typescript'
]
}
}
]
},
{
test: /\.(scss|css)$/,
use: ['style-loader', 'css-loader', 'sass-loader']
}
]
},
resolve: {
extensions: ['.ts', '.tsx', '.js', '.jsx'],
alias: {
'react-dom': '@hot-loader/react-dom'
},
preferRelative: true,
modules: [path.resolve(__dirname, 'src'), 'node_modules']
},
plugins: [
new ForkTsCheckerWebpackPlugin({
typescript: {
configFile: path.resolve(__dirname, 'tsconfig.json')
}
}),
new Dotenv({
path: path.resolve(__dirname, '.env')
})
]
};
我的ESLINT配置(和webpack一起在根目录下的.eslintrc中):
{
"parser": "@babel/eslint-parser",
"extends": [
"standard",
"standard-react",
"plugin:prettier/recommended",
"prettier/standard",
"prettier/react",
"plugin:@typescript-eslint/eslint-recommended"
],
"env": {
"node": true
},
"parserOptions": {
"requireConfigFile": false,
"ecmaVersion": 2020,
"ecmaFeatures": {
"legacyDecorators": true,
"jsx": true
}
},
"settings": {
"react": {
"version": "16"
},
"import/resolver": {
"node": {
"extensions": [".js", ".jsx", ".ts", ".tsx"],
"moduleDirectory": ["node_modules", "src/"]
}
}
},
"rules": {
"space-before-function-parent": 0,
"react/prop-types": 0,
"react/jsx-handler-names": 0,
"no-unused-expressions": "off",
"react/jsx-fragments": 0,
"react/no-unused-prop-types": 0,
"import/export": 0,
"react-hooks/rules-of-hooks": "error",
"react-hooks/exhaustive-deps": "warn",
"no-console": "warn",
"no-restricted-imports": [
"error",
{
"patterns": [".*"]
}
],
"import/order": [
"error",
{
"groups": ["builtin", "external", "internal"],
"pathGroups": [
{
"pattern": "react",
"group": "external",
"position": "before"
}
],
"pathGroupsExcludedImportTypes": ["react"]
}
]
},
"plugins": [
"react-hooks",
"jsx-a11y",
"react",
"prettier",
"@typescript-eslint"
]
}
发布于 2021-11-22 04:24:22
也许ignorePatterns会帮你。
您可以在配置文件中使用ignorePatterns告诉ESLint忽略特定的文件和目录。ignorePatterns模式遵循与.eslintignore相同的规则。
// .eslintrc
{
...
...
ignorePatterns: ['dist']
}
https://stackoverflow.com/questions/70058959
复制相似问题