当运行npm-run-webpackforbuildforproduction模式时,我无法在dist文件夹中为css创



这是我的webpackconfig文件的代码。

const currentTask=process.env.nmp_lifecycle_event

const path=require("path"(

const MiniCsExtractPlugin=require('mini-css-extract-plugin'(

常量配置={条目:'/app/app.js’,

output:{
    filename:'myBundle.[hash].js',
    path: path.resolve(__dirname,'dist')
},
plugins:[],
mode:'development',
devServer:{
    port:8080,
    static:path.resolve(__dirname, 'dist'),
    hot:true
},
module:{
    rules:[
    {
       test:/.scss$/,
       use:['style-loader', 'css-loader', 'sass-loader']
    },
    {
    
        test:/.js$/,
        exclude:/(node_modules|bower_components)/,
        use:{
            loader:"babel-loader",
            options:{
                presets:['@babel/preset-env', '@babel/preset-react']
            }
        }
    }
    ]
}
}
if(currentTask == "build"){
    config.mode = "production"
    config.module.rules[0].use[0]=MiniCssExtractPlugin.loader
    config.plugins.push(new MiniCssExtractPlugin({filename:'main.[hash].css'}))
}

module.exports=配置

我试过你的代码,它运行得很好,你只在第一行有一个拼写错误(npm拼写错误(:

const currentTask=process.env.nmp_lifecycle_event

应该是:

const currentTask=process.env.npm_lifecycle_event

此外,请确保您已将.scss文件导入javascript中的某个位置,并且您正在使用npm run build构建应用程序。

最新更新