antd less module build failed with typings-for-css-modules-loader
zhaoyu69 opened this issue · 1 comments
zhaoyu69 commented
//package.json
"dependencies": {
"@types/react": "^16.3.14",
"@types/react-dom": "^16.0.5",
"antd": "^3.5.2",
"babel-preset-stage-2": "^6.24.1",
"mobx": "^4.2.1",
"mobx-react": "^5.1.2",
"react": "^16.3.2",
"react-dom": "^16.3.2",
"react-router-dom": "^4.2.2"
},
"devDependencies": {
"awesome-typescript-loader": "^5.0.0",
"babel-core": "^6.26.3",
"babel-loader": "^7.1.4",
"babel-plugin-transform-decorators-legacy": "^1.3.4",
"babel-preset-env": "^1.6.1",
"babel-preset-react": "^6.24.1",
"css-loader": "^0.28.11",
"html-webpack-plugin": "^3.2.0",
"less": "^3.0.4",
"less-loader": "^4.1.0",
"source-map-loader": "^0.2.3",
"style-loader": "^0.21.0",
"ts-import-plugin": "^1.4.4",
"typescript": "^2.8.3",
"typings-for-css-modules-loader": "^1.7.0",
"url-loader": "^1.0.1",
"webpack": "^4.8.1",
"webpack-cli": "^2.1.3",
"webpack-dev-server": "^3.1.4"
}
//webpack.config.js
// webpack.config.js
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const tsImportPluginFactory = require('ts-import-plugin')
const webpack = require('webpack');
module.exports = {
entry: {
index:'./src/index.js',
},
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, 'dist')
},
devtool: "source-map",
resolve: {
extensions: ['.ts', '.tsx', '.js', '.jsx', '.less', '.css']
},
// mode:'development',
module: {
rules: [
{
test: /\.css$/,
use: ['style-loader', 'css-loader']
},
{
test: /\.less/,
use: [
'style-loader',
'typings-for-css-modules-loader?modules&importLoaders=1&localIdentName=[name]__[local]___[hash:base64:5]&namedExport&camelCase&less!less-loader'
]
},
{
test: /\.(png|svg|jpg|gif)$/,
use: ['url-loader']
},
{
test: /\.(woff|woff2|eot|ttf|otf)$/,
use: ['url-loader']
},
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader'
}
},
// All files with a '.ts' or '.tsx' extension will be handled by 'awesome-typescript-loader'.
{
test: /\.tsx?$/,
loader: "awesome-typescript-loader",
options: {
getCustomTransformers: () => ({
before: [ tsImportPluginFactory({
libraryName: 'antd',
libraryDirectory: 'es',
style: true,
}) ]
}),
},
exclude: /node_modules/
},
]
},
plugins: [
new HtmlWebpackPlugin({
title: 'production',
template: './index.html'
}),
new webpack.NamedModulesPlugin(),
new webpack.HotModuleReplacementPlugin(),
new webpack.WatchIgnorePlugin([
/(less|css)\.d\.ts$/
])
],
devServer: {
contentBase: './dist',
hot: true
},
};
//tsconfig.json
{
"compilerOptions": {
"outDir": "./dist/",
"sourceMap": true,
"noImplicitAny": true,
"module": "commonjs",
"target": "es2017",
"jsx": "react",
"removeComments": true,
"experimentalDecorators": true,
"allowJs": true
},
"include": [
"./src/**/*"
]
}
jardakotesovec commented
@zhaoyu69 Hi, I think this error does not have anything to do with this module.
I solved this problem with:
{
test: /\.less$/,
use: [
MiniCssExtractPlugin.loader,
'css-loader',
{
loader: 'less-loader',
options: { javascriptEnabled: true, modifyVars: themeVariables },
},
],
},
Where the javascriptEnabled is important part :-). And I see in your repo that you already figured that out.. so can you close it?