-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
webpack相关 #85
Comments
css-loader options modules为true时,antd样式失效当webpack配置了css-loader options modules为true时,会发现通过import导入的antd样式失效了 app.js import React from 'react';
import { Input } from 'antd';
import 'antd/dist/antd.less';
import styles from './index.less';
const App = () => {
return (
<div className={styles.container}>
<Input />
<div className={styles.txt}>detail</div>
</div>
);
};
export default App; 问题原因:项目中样式采用css modules的写法,构建之后会被重命名。如果项目中引入了antd的样式,则会导致样式加载不到问题 当遇到这种情况时,有下列两种解决方案:
如果是全局引入的antd.css文件 import 'antd/dist/antd.css'; 此时webpack配置: {
test: /\.css$/,
// 针对node_modules中的文件,不开启css modules
exclude: /src/,
use: [
{
loader: 'style-loader',
options: {
singleton: true,
},
},
{
loader: 'css-loader',
},
{
loader: 'postcss-loader',
},
],
},
{
test: /\.css$/,
exclude: /node_modules/,
use: [
{
loader: 'style-loader',
options: {
singleton: true,
},
},
{
loader: 'css-loader',
options: {
modules: true,
},
},
{
loader: 'postcss-loader',
},
],
}, 如果是全局引入antd.less文件 import 'antd/dist/antd.less'; 此时webpack配置 {
test: /\.less$/,
exclude: /src/,
use: [
'style-loader',
{
loader: 'css-loader',
},
{
loader: 'postcss-loader',
options: {
postcssOptions: {
plugins: [require('autoprefixer')],
},
},
},
{
loader: 'less-loader',
options: {
lessOptions: {
javascriptEnabled: true,
},
},
},
],
},
{
test: /\.less$/,
exclude: /node_modules/,
use: [
'style-loader',
{
loader: 'css-loader',
options: {
modules: true,
},
},
{
loader: 'postcss-loader',
options: {
postcssOptions: {
plugins: [require('autoprefixer')],
},
},
},
{
loader: 'less-loader',
options: {
lessOptions: {
javascriptEnabled: true,
},
},
},
],
}, 这样配置后,在业务中既可以使用import styles from 'xxx'的语法,也不会导致antd的样式失效了 |
webpack打包vue报错export 'default' (imported as 'Vue') was not found in 'vue'https://blog.csdn.net/angelia620/article/details/121278156 webpack配置文件后运行报错TypeError: VueLoaderPlugin is not a constructor老版本: const VueLoaderPlugin = require('vue-loader/lib/plugin') 新版本: const { VueLoaderPlugin } = require('vue-loader') |
webpack5升级过程遇到的一些坑版本相关信息
问题
在
在webpack5.x中,发现很多关于
在运行过程中出现了很多这样的报错信息,是由于在webpack5中移除了nodejs核心模块的polyfill自动引入,所以需要手动引入,如果打包过程中有使用到nodejs核心模块,webpack会提示进行相应配置
为
官方给出的问题原因是
不过我在本地创建了一个新的项目,版本信息如下,还是存在上面的那个报错信息,demo地址github issue
官方答复:guthub issue
|
umi3 优化lodash体积yarn add lodash-webpack-plugin config.js import { defineConfig } from 'umi';
import LodashModuleReplacementPlugin from 'lodash-webpack-plugin';
export default defineConfig({
...
chainWebpack(config) {
config.plugin('lodash-webpack-plugin').use(
new LodashModuleReplacementPlugin({
collections: true,
paths: true,
}),
);
})
}) |
lodash-webpack-plugin iteratee 不是函数new LodashModuleReplacementPlugin({
collections: true,
paths: true,
shorthands: true
}) |
使用import styles from './index.less'导入less时,styles报错
webpack.config.js
app.js
此时跑起项目后,会报错:
正确使用方式:修改css-loader options modules为true
The text was updated successfully, but these errors were encountered: