laravel-mix / webpack,忽略要导出的Sass加载文件(字体)

问题描述 投票:0回答:1

我正在尝试跳过要加载的依赖项加载字体(带有url())。我使用了ignore-loader模块。

mix.webpackConfig({
    module: {
        rules: [
            {
                test: /context-menu-icons\.(eot|ttf|otf|woff|woff2)$/,
                loader: 'ignore-loader'
            }
        ]
    }
});

问题是它会产生空文件。我期望的行为是根本不输出这些文件。

mix compile outputs empty filesenter image description here

其原因是在node_modules中的依赖性中

@font-face {
  font-family: '#{$context-menu-icon-font-name}';
  src: url('#{$context-menu-icon-font-path}#{$context-menu-icon-font-name}.eot?#{$context-menu-icons-cachebust}');
  src: url('#{$context-menu-icon-font-path}#{$context-menu-icon-font-name}.eot?#{$context-menu-icons-cachebust}#iefix') format('embedded-opentype'),
  url('#{$context-menu-icon-font-path}#{$context-menu-icon-font-name}.woff2?#{$context-menu-icons-cachebust}') format('woff2'),
  url('#{$context-menu-icon-font-path}#{$context-menu-icon-font-name}.woff?#{$context-menu-icons-cachebust}') format('woff'),
  url('#{$context-menu-icon-font-path}#{$context-menu-icon-font-name}.ttf?#{$context-menu-icons-cachebust}') format('truetype');
  font-weight: normal;
  font-style: normal;
}

是否有一种方法可以仅从我的dist文件夹中的输出/复制中忽略这些文件?

laravel webpack laravel-mix css-loader sass-loader
1个回答
0
投票

我找不到解决方案,因为字体是从scss文件加载的。因此,将选项与file-loader配合使用以防止发射文件将不起作用。这些文件中将有一个字符串,其内容为module.exports = ...

在所有情况下,字体文件将被显示为空或不为空。

所以我在这些选项上使用了clean-webpack-plugin

const { CleanWebpackPlugin } = require('clean-webpack-plugin');
...
mix.webpackConfig({
    plugins: [
        new CleanWebpackPlugin({
            // dry: true,
            verbose: true,
            // Automatically remove all unused webpack assets on rebuild
            cleanStaleWebpackAssets: false,
            // Do not allow removal of current webpack assets
            protectWebpackAssets: false,
            cleanOnceBeforeBuildPatterns: [
                '**/*', // clean all
                '!views','!views/**/*', // ignore views folder
                '!lang','!lang/**/*',  // ignore lang folder
            ],
            cleanAfterEveryBuildPatterns: [
                'fonts/vendor' // remove fonts/vendor folder after build and watch
            ],
        }),
    ]
});
...
© www.soinside.com 2019 - 2024. All rights reserved.