微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Webpack @import顺序scss,css未保留

如何解决Webpack @import顺序scss,css未保留

当前结果

  1. SimpleBar
  2. 引导程序
  3. 主要

所需结果

  1. 引导程序
  2. SimpleBar
  3. 主要

“。css”文件似乎先捆绑在一起。

webpack.config.js

const path = require('path');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');

module.exports = {
    mode: 'development',entry: './src/scripts/app.js',output: {
        filename: 'scripts/app.js'
    },plugins: [
        new MiniCssExtractPlugin({
            filename: 'styles/app.css'
        })
    ],module: {
        rules: [
            {
                test: /\.(css|scss)$/,use: [
                    {
                        loader: MiniCssExtractPlugin.loader
                    },{
                        loader: 'css-loader',options: {
                            sourceMap: true
                        }
                    },{
                        loader: 'postcss-loader',options: {
                            postcssOptions: {
                                plugins: [
                                    'autoprefixer'
                                ]
                            },sourceMap: true
                        }
                    },{
                        loader: 'resolve-url-loader',{
                        loader: 'sass-loader',options: {
                            sourceMap: true
                        }
                    }
                ]
            },{
                test: /\.(eot|otf|svg|ttf|woff|woff2)$/,use: [
                    {
                        loader: 'file-loader',options: {
                            outputPath: 'fonts',publicPath: '../fonts'
                        }
                    }
                ]
            }
        ]
    },watch: true
};

src / scripts / app.js

import '../styles/app.scss';

src / styles / app.scss

@import '~bootstrap/scss/bootstrap';
@import '~simplebar/dist/simplebar.css';
@import 'main';

请注意,“ SimpleBar”不带有可解决问题的“ .scss”文件。我也不想从“ node_modules”目录中重命名“ .css”文件

  "devDependencies": {
    "autoprefixer": "^9.8.6","css-loader": "^4.3.0","file-loader": "^6.1.0","mini-css-extract-plugin": "^0.11.1","postcss": "^7.0.32","postcss-loader": "^4.0.1","resolve-url-loader": "^3.1.1","sass": "^1.26.10","sass-loader": "^10.0.2","webpack": "^4.44.1","webpack-cli": "^3.3.12"
  }

#1解决方案(我不太喜欢)

src / scripts / app.js

import '../styles/vendor.scss'; // Bootstrap and other goodies
import 'simplebar/dist/simplebar.css';
import '../styles/main.scss';

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。