umijs / babel-plugin-import

Modularly import plugin for babel.
3.16k stars 404 forks source link

按需加载less没问题,但是使用extract-text-webpack-plugin就报错了 #301

Open Vibing opened 5 years ago

Vibing commented 5 years ago

部分依赖:

{
"@babel/core": "^7.2.0",
"babel-loader": "^8.0.4",
"babel-plugin-import": "^1.11.0",
"webpack": "^4.28.4",
"typescript": "^3.2.2",
"less": "^3.9.0",
"less-loader": "^4.1.0",
"style-loader": "^0.23.1"
}

tsconfig.json

{
  "compilerOptions": {
    "target": "esnext",
    "module": "esnext",
    "moduleResolution": "node",
    "importHelpers": true,
    "jsx": "react",
    "esModuleInterop": true,
    "sourceMap": true,
    "outDir": "lib",
    "baseUrl": ".",
    "paths": {
      "@/*": ["src/*"]
    },
    "allowSyntheticDefaultImports": true
  }
}

webapck.config.js

const path = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const ExtractTextPlugin = require("extract-text-webpack-plugin");

module.exports = {
    mode: 'development',
    entry: './src/index',
    devtool: 'inline-source-map',
    performance: {
        hints: false,
        maxEntrypointSize: 512000,
        maxAssetSize: 512000
    },
    output: {
        path: path.resolve(__dirname, 'dist'),
        filename: 'app.bundle.js'
    },
    resolve: {
        extensions: ['.ts', '.tsx', '.less', '.js', '.json']
    },
    module: {
        rules: [{
            test: /\.(ts|js)x?$/,
            exclude: /node_modules/,
            use: [{
                loader: 'babel-loader'
            }]
        }, {
            test: /\.css$/,
            use: ['style-loader', 'css-loader']
        }, {
            test: /\.less$/,
            use: ExtractTextPlugin.extract({
                fallback: 'style-loader',
                use: [{
                    loader: 'style-loader',
                }, {
                    loader: 'css-loader',
                }, {
                    loader: 'less-loader',
                    options: {
                        javascriptEnabled: true
                    }
                }]
            })
        }]
    },
    plugins: [
        new ExtractTextPlugin('style.css'),
        new HtmlWebpackPlugin({
            template: path.resolve(__dirname, 'index.ejs'),
            templateParameters: {
                title: 'test'
            }
        })
    ],
    devServer: {
        host: 'localhost',
        port: 3000
    }
}

报错信息:

err

我应该如何解决? 谢谢🙂🙂🙂🙂

Vibing commented 5 years ago

没有大佬帮忙看看吗。。。

chenshuhong commented 5 years ago

webpack4用extract-text-webpack-plugin@next或者mini-css-extract-plugin

Vibing commented 5 years ago

webpack4用extract-text-webpack-plugin@next或者mini-css-extract-plugin

已经解决了 谢谢