require('datatables.net-buttons') has made a lot of errors

require('datatables.net-buttons') has made a lot of errors

misterztqmisterztq Posts: 5Questions: 3Answers: 0
edited July 2018 in Free community support

require( 'jszip' );
require( 'pdfmake' );
require('datatables.net');
require('datatables.net-buttons');
require('datatables.net-buttons/js/buttons.flash.js');
require('datatables.net-buttons/js/buttons.html5.js');
When I use webpack to pack up, there're many errors liked Module not found: Error: Can't resolve 'fs' in '...'

Answers

  • allanallan Posts: 63,252Questions: 1Answers: 10,420 Site admin

    Can you send me your webpack config file please?

    Allan

  • misterztqmisterztq Posts: 5Questions: 3Answers: 0

    const path = require("path");
    const webpack = require('webpack');

    const HTMLWebpackPlugin = require("html-webpack-plugin");

    const CleanWebpackPlugin = require("clean-webpack-plugin");

    const ExtractTextPlugin = require("extract-text-webpack-plugin");

    const config = require("./config");

    let HTMLPlugins = [];

    let Entries = {};

    config.HTMLDirs.forEach((page) => {
    const htmlPlugin = new HTMLWebpackPlugin({
    filename: ${page}.html,
    template: path.resolve(__dirname, ../src/html/${page}.html),
    chunks: [page, 'commons'],
    });
    HTMLPlugins.push(htmlPlugin);
    Entries[page] = path.resolve(__dirname, ../src/js/${page}.js);
    });

    module.exports = {
    entry:Entries,
    devtool:"cheap-module-source-map",
    output:{
    filename:"js/[name]-[chunkhash].js",
    path:path.resolve(__dirname,"../dist")
    },

    module:{
        rules:[
            {
                test: /\.js$/,
                //exclude: /node_modules/,
                use: {
                    loader: 'babel-loader',
                    options: {
                        presets: ['env']
                    }
                }
            },
            {
                test:/\.(scss|css)$/,
                //exclude: /node_modules/,
                use: ExtractTextPlugin.extract({
                    fallback: "style-loader",
                    publicPath: config.cssPublicPath,
                    use: [{
                        loader:"css-loader",
                        options:{
                            sourceMap: true,
                            minimize:true
                        }
                    },
                        {
                            loader:"postcss-loader",
                            options: {
                                sourceMap: true
                            }
                        },
                        {
                            loader: "sass-loader",
                            options: {
                                sourceMap: true
                            }
                        }
                    ]
                })
            },
            {
                test: /\.html$/,
                use: [ {
                    loader: 'html-loader',
                }],
            },
            {
                test: /\.(jpg|png|ico|jpeg|gif)$/,
                use:{
                    loader:"file-loader",
                    options:{
    
                        name:"[name].[ext]",
    
                        outputPath:config.imgOutputPath
                    }
                }
            },
            {
                test: /\.(svg|woff|woff2|eot|ttf|otf)$/,
                use:[{
                    loader: "file-loader",
                    options: {
                        name: "[name].[ext]",
                        outputPath:config.fontOutputPath
                    }
                }]
            },
            { parser: { amd: false } } 
        ],
    },
    //target: 'node',
    //node:{fs:'empty'},
    plugins:[
        new webpack.ProvidePlugin({
            $: "jquery",
            jQuery: "jquery"
        }),
        //new CleanWebpackPlugin(["dist"]),
        new CleanWebpackPlugin(["dist"], {
            root: path.resolve(__dirname, "../"),
            verbose: true,
            dry: false
        }),
        new ExtractTextPlugin(config.cssOutputPath),
        ...HTMLPlugins
    ]
    

    };

  • sunixsunix Posts: 4Questions: 0Answers: 0

    You need to use client side already built version of pdfmake:

    require('pdfmake/build/pdfmake.js');
    require('pdfmake/build/vfs_fonts.js');
    
This discussion has been closed.