I have problem with configure laravel-mix to work properly with React, Typescript, Ant Design. I started with React with JS without TypeScript and it worked nicely (Ant Design styles were being imported with overridden variables).
But after adding Typescript, importing Ant Design styles stopped working. To make it work I need to manually import antd styles file into my main style .scss file. But in that case, the bundle becomes huge and variables overriding doesn't work.
webpack.mix.js:
const mix = require('laravel-mix');
const AntdScssThemePlugin = require('antd-scss-theme-plugin');
mix.webpackConfig({
module: {
rules: [
{
test: /\.less$/,
use: [
AntdScssThemePlugin.themify({
loader: "less-loader",
options: {
javascriptEnabled: true
}
})
],
},
{
test: /\.tsx?$/,
loader: "ts-loader",
exclude: /node_modules/,
options: {
transpileOnly: true
}
}
]
},
resolve: {
extensions: ["*", ".js", ".jsx", ".vue", ".ts", ".tsx", ".less", ".scss", ".css"]
},
plugins: [
new AntdScssThemePlugin('./resources/sass/_theme.scss') // theme customization
]
});
mix.setPublicPath('../public_html')
.react('resources/js/app.js', '../public_html/js')
.sass('resources/sass/app.scss', '../public_html/css')
.extract(['react', 'react-dom', 'react-router-dom', 'react-redux', 'redux', 'redux-thunk', 'axios'])
.sourceMaps(!mix.inProduction(), 'source-map')
.version();
.babelrc:
{
"presets": [
[
"@babel/preset-env", {
"targets": {
"browsers": [ ">5%", "not op_mini all"]
}
}
],
"@babel/preset-react"
],
"plugins": [
"@babel/plugin-proposal-class-properties",
["import", {
"libraryName": "antd",
"libraryDirectory": "es",
"style": true
}]
]
}
Ant Design documentation describes use case with create-react-app but I need to make it work with laravel-mix.
Mayble someone struggled with similar problem.