加载程序不适用于通过别名解析的文件
Loaders don't apply to files resolved through the alias
我假设 webpack 加载程序不适用于通过别名解析的文件。
有人遇到过这样的问题吗?或者有人可以反驳这个假设吗?
完整上下文:
我开发自己的 npm 包 my-package
。另外,我有一个使用这个 my-package
的测试项目。为了改善开发体验,我想创建一个单独的 webpack 配置,它将 node_modules
中的 my-package
替换为本地包 src 文件。
它有效,但我在 my-package
个文件中遇到下一个错误:
Support for the experimental syntax 'classProperties' isn't currently enabled (35:20):
33 |
34 | class AddressForm extends PureComponent {
> 35 | static propTypes = {
| ^
36 | // eslint-disable-next-line react/require-default-props
37 | onSubmit: (props, propName) => {
38 | if (
Add @babel/plugin-proposal-class-properties
我的 .babelrc
文件中有 @babel/plugin-proposal-class-properties
,我在测试项目文件中使用 class 属性。
这是我的 webpack 配置:
const path = require('path');
const HtmlWebPackPlugin = require('html-webpack-plugin');
module.exports = {
mode: 'development',
devtool: 'inline-source-map',
entry: {
'integration-test-page': './src/integration-test-page/index.jsx',
},
output: {
filename: '[name].bundle.js',
path: path.resolve(__dirname, 'dist'),
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
},
},
{
test: /\.html$/,
use: [
{
loader: 'html-loader',
},
],
},
],
},
plugins: [
new HtmlWebPackPlugin({
template: './src/integration-test-page/index.html',
filename: './index.html',
}),
],
resolve: {
alias: {
'my-package': path.resolve(
__dirname,
'../my-package/src/index.js'
),
},
extensions: ['.js', '.jsx'],
},
};
我找到了修复它的方法。我必须将 babelrcRoots: ['.', '../'],
添加到我的 babel.config.js
这里是关于 monorepos 的 babel 配置的详细信息 https://babeljs.io/docs/en/config-files#monorepos
我假设 webpack 加载程序不适用于通过别名解析的文件。 有人遇到过这样的问题吗?或者有人可以反驳这个假设吗?
完整上下文:
我开发自己的 npm 包 my-package
。另外,我有一个使用这个 my-package
的测试项目。为了改善开发体验,我想创建一个单独的 webpack 配置,它将 node_modules
中的 my-package
替换为本地包 src 文件。
它有效,但我在 my-package
个文件中遇到下一个错误:
Support for the experimental syntax 'classProperties' isn't currently enabled (35:20):
33 |
34 | class AddressForm extends PureComponent {
> 35 | static propTypes = {
| ^
36 | // eslint-disable-next-line react/require-default-props
37 | onSubmit: (props, propName) => {
38 | if (
Add @babel/plugin-proposal-class-properties
我的 .babelrc
文件中有 @babel/plugin-proposal-class-properties
,我在测试项目文件中使用 class 属性。
这是我的 webpack 配置:
const path = require('path');
const HtmlWebPackPlugin = require('html-webpack-plugin');
module.exports = {
mode: 'development',
devtool: 'inline-source-map',
entry: {
'integration-test-page': './src/integration-test-page/index.jsx',
},
output: {
filename: '[name].bundle.js',
path: path.resolve(__dirname, 'dist'),
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
},
},
{
test: /\.html$/,
use: [
{
loader: 'html-loader',
},
],
},
],
},
plugins: [
new HtmlWebPackPlugin({
template: './src/integration-test-page/index.html',
filename: './index.html',
}),
],
resolve: {
alias: {
'my-package': path.resolve(
__dirname,
'../my-package/src/index.js'
),
},
extensions: ['.js', '.jsx'],
},
};
我找到了修复它的方法。我必须将 babelrcRoots: ['.', '../'],
添加到我的 babel.config.js
这里是关于 monorepos 的 babel 配置的详细信息 https://babeljs.io/docs/en/config-files#monorepos