我运行npm run dev
,控制台会在下面显示警告,这是我的基本webpack配置,我在条目中使用了'babel-polyfill',并且在babel-loader配置中排除了node_modules
目录:
module.exports = {
entry: {
index: ['babel-polyfill', entry]
},
output: {
path: dist
},
resolve: {
extensions: ['.web.js', '.js', '.jsx', '.less', '.scss', '.css', '.json', '.png', '.jpg', '.jpeg'],
alias: {
'@': src,
'@utils': path.resolve(src, 'utils'),
'@common': path.resolve(src, 'common'),
}
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
include: src,
use: {
loader: 'babel-loader?cacheDirectory'
}
}, {
test: /\.(eot|woff|svg|ttf|woff2|gif|appcache)(\?|$)/,
exclude: /^node_modules$/,
loader: 'url-loader?name=fonts/[name].[ext]',
include: src
}, {
test: /\.(png|jpg)$/,
// exclude: /^node_modules$/,
loader: 'url-loader?limit=8192&name=images/[hash:8].[name].[ext]'
// include: [SRC_PATH]
}, { test: /\.(svg)$/i,
loader: 'svg-sprite-loader',
include: [
require.resolve('antd').replace(/warn\.js$/, '')
// path.resolve(__dirname, 'images/'),
]}
]
},
optimization: {
runtimeChunk: {
name: 'runtime'
},
splitChunks: {
chunks: 'all',
minSize: 30000,
maxSize: 200000,
minChunks: 1,
maxAsyncRequests: 5,
maxInitialRequests: 4,
automaticNameDelimiter: '_',
cacheGroups: {
libs_antd: {
name: 'libs_antd',
test: path.resolve(root, 'node_modules', 'antd'),
chunks: 'async',
priority: -8,
reuseExistingChunk: true
},
verdors: {
name: 'verdors',
test: path.resolve(root, 'node_modules'),
chunks: 'initial',
priority: -10
},
node_commons: {
name: 'node_commons',
test: path.resolve(root, 'node_modules'),
chunks: 'async',
minChunks: 2,
priority: -10,
reuseExistingChunk: true
}
}
},
usedExports: true
},
plugins
};
和警告消息:
WARNING in ./node_modules/[email protected]@antd/lib/locale/hu_HU.d.ts 1:8
Module parse failed: Unexpected token (1:8)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
> declare const _default: {
| locale: string;
| Pagination: any;
@ ./node_modules/antd/lib/locale lazy ^\.\/.*$ namespace object ./hu_HU.d.ts
@ ./src/app/component/index.js
@ ./src/app/model/container.js
@ ./src/app/index.js
@ ./src/router.js
@ ./src/entry.js
@ multi babel-polyfill ./src/entry
我以为不应解析node_modules中的代码,不知道为什么会出现警告?有任何想法吗?谢谢。
您没有从ts
中排除node_modules
个文件。您可能需要在规则中添加ts
文件以将其忽略,如下所示:
{
test: /\.(js|jsx|ts|tsx)$/,
exclude: /node_modules/,
include: src,
use: {
loader: 'babel-loader?cacheDirectory'
}
},