使用 Silverstripe 模板进行净化时出现语法错误(purifycss-webpack-plugin、webpack、Silverstripe 模板)

SyntaxError when purifying with Silverstripe templates (purifycss-webpack-plugin, webpack, Silverstripe template)

我尝试将 purifycss-webpack 与 webpack 和 silverstripe 模板一起使用。 Purifycss 文档说它可以与模板和任何使用 CSS 选择器的东西一起使用。我把一切都安排好了。当我尝试 运行 时,出现此错误:

(function (exports, require, module, __filename, __dirname) { <section
SyntaxError: Unexpected token <

所以在我看来模板无法读取。

这是我的 webpack 配置:

const glob = require('glob-all');
const path = require('path')
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack- 
plugin');
const {ImageminWebpackPlugin} = require("imagemin-webpack");
const imageminOptipng = require("imagemin-optipng");
const imageminGifsicle = require("imagemin-gifsicle");
const imageminJpegtran = require("imagemin-jpegtran");
const imageminSvgo = require("imagemin-svgo");
const PurifyCSSPlugin = require('purifycss-webpack');

module.exports = {
  entry: {
    app: ['./src/js/entry.js', './src/css/main.scss'],
},
output: {
    filename: "js/[name].min.js",
    path: path.resolve(__dirname, "./dist"),
},
mode: 'production',
module: {
    rules: [
        {
            test: /\.ss/,
            loader: 'silverstripe-template-loader'
        },
        {
            test: /\.(scss|css)$/,
            use: [
                {
                    loader: 'style-loader'
                },
                {
                    loader: MiniCssExtractPlugin.loader
                },
                {
                    loader: 'css-loader',
                    options: {
                        sourceMap: true
                    }
                },
                {
                    loader: 'resolve-url-loader',
                },
                {
                    loader: 'sass-loader',
                    options: {
                        sourceMap: true
                    }
                }
            ]

        },
        {
            test: /\.js$/,
            exclude: /(node_modules)/,
            use: {
                loader: 'babel-loader',
                options: {
                    presets: ['babel-preset-env']
                }
            }
        },
        {
            test: /\.(png|svg|jpe?g|gif)$/,
            loader: 'file-loader',
            options: {
                name: 'images/[name].[ext]',
                publicPath: '/public/dist/',
            }
        },
    ]
},
plugins: [
    new CleanWebpackPlugin(['dist']),
    new MiniCssExtractPlugin({
        filename: 'css/[name].min.css',
        chunkFilename: "[id].css"
    }),
    new PurifyCSSPlugin({
        paths:  glob.sync([
      path.join(require('/Users/foobar/Desktop/hsb/www/app/templates/DNADesign/Elemental/Layout/FBNewsHolder.ss')),
        ]),
    }),
    new ImageminWebpackPlugin({
        imageminOptions: {
            plugins:[
                imageminOptipng({
                    optimizationLevel: 5
                }),
                imageminGifsicle({
                    interlaced: true
                }),
                imageminJpegtran({
                    progressive: true
                }),
                imageminSvgo({
                    removeViewBox: true
                })
            ]
        }
    })
  ],
}

他们是将 purifycss 与 silverstripe tempaltes 一起使用的方法吗?
谁能帮我解决这个问题???

我成功了。以防万一有人遇到同样的问题她是我的 webpack 配置有效

const glob = require('glob-all');
const path = require('path')
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin');
const {ImageminWebpackPlugin} = require("imagemin-webpack");
const imageminOptipng = require("imagemin-optipng");
const imageminGifsicle = require("imagemin-gifsicle");
const imageminJpegtran = require("imagemin-jpegtran");
const imageminSvgo = require("imagemin-svgo");
const PurifyCSSPlugin = require("purifycss-webpack");
const PATHS = path.join(__dirname, '../../www/app/templates/');



module.exports = {
    entry: {
        app: ['./src/js/entry.js', './src/css/main.scss'],
    },
    output: {
        filename: "js/[name].min.js",
        path: path.resolve(__dirname, "./dist"),
    },
    mode: 'production',
    module: {
        rules: [
            {
                test: /\.ss/,
                loader: 'silverstripe-template-loader'
            },
            {
                test: /\.(scss|css)$/,
                use: [
                    {
                        loader: 'style-loader'
                    },
                    {
                        loader: MiniCssExtractPlugin.loader
                    },
                    {
                        loader: 'css-loader',
                        options: {
                            sourceMap: true
                        }
                    },
                    {
                        loader: 'resolve-url-loader',
                    },
                    {
                        loader: 'sass-loader',
                        options: {
                            sourceMap: true
                        }
                    }
                ]

            },
            {
                test: /\.js$/,
                exclude: /(node_modules)/,
                use: {
                    loader: 'babel-loader',
                    options: {
                        presets: ['babel-preset-env']
                    }
                }
            },
            {
                test: /\.(png|svg|jpe?g|gif)$/,
                loader: 'file-loader',
                options: {
                    name: 'images/[name].[ext]',
                    publicPath: '/public/dist/',
                }
            },
        ]
    },
    plugins: [
        new CleanWebpackPlugin(['dist']),
        new MiniCssExtractPlugin({
            filename: 'css/[name].min.css',
            chunkFilename: "[id].css"
        }),
        new PurifyCSSPlugin({
            paths:  glob.sync([
                path.join(PATHS + 'DNADesign/Elemental/Layout/FBNewsHolder.ss'),
            ]),

        }),
        new ImageminWebpackPlugin({
            imageminOptions: {
                plugins:[
                    imageminOptipng({
                        optimizationLevel: 5
                    }),
                    imageminGifsicle({
                        interlaced: true
                    }),
                    imageminJpegtran({
                        progressive: true
                    }),
                    imageminSvgo({
                        removeViewBox: true
                    })
                ]
            }
        })
    ],
}

我不知道如何使用节点路径模块。这就是问题所在。