0

Currently, I use a shitty hacky webpack solution to watch, copy and transform files. I'd like to know if there was a dedicated package for this. I don't need any bundling of sorts.

This is my current webpack config

// webpack.config.js

const path = require('path');
const nodeExternals = require('webpack-node-externals');
const CopyWebpackPlugin = require('copy-webpack-plugin');

const
    PATH_MAIN = '/',
    PATH_M = '../',
    PATH_ALT = '../../../ALT'
;

const clientAndServerConfig = {
    mode: 'production',
    target: 'node', // in order to ignore built-in modules like path, fs, etc.
    resolve: { 
        extensions: ['.json', '.js', '.jsx', '.ts', '.tsx']
    },
    module: {
        rules: [
            {
                test: /\.js$/,
                exclude: ['/node_modules/', PATH_MAIN + 'client/browsers/', '/\.eslintrc$/']
            },
        ]
    },
    entry: {
        '../packages/server': './server',
    },
    output: {
        path: path.resolve(__dirname),
        filename: '[name]/bundle.js',
    },
    externals: [nodeExternals()],
    plugins: [
        new CopyWebpackPlugin([
                { from: 'server', to: PATH_M + 'packages/server', force: true, cache: true },
                { from: 'server-ternationalization/browsers', to: PATH_M + 'server/client/browsers/languages', force: true, cache: true },
                { from: 'client', to: PATH_M + 'client_packages/server', force: true, cache: true },
                { from: 'dlcpacks', to: PATH_M + 'client_packages/dlcpacks', force: true, cache: true },
                //
                /*{ from: 'package.json', to: PATH_ALT, force: true, cache: true },
                { from: 'ALT/server.cfg', to: PATH_ALT, force: true, cache: true },
                { from: 'ALT/resource.cfg', to: PATH_ALT + '/resources/server', force: true, cache: true },
                { from: 'server', to: PATH_ALT + '/resources/server/server', force: true, cache: true },
                {
                    from: 'client', to: PATH_ALT + '/resources/server/client', force: true, cache: true,
                    transform(content, path) {
                        // @param content: Buffer
                        // @param src: String 
                        // @return Buffer
                        return Promise.resolve(Buffer.from(content.toString().replace(new RegExp(/const\s+(\w+)\s+=\s+require\('([^']+)'\);?/), `import $1 from '$2';`), 'utf8'));
                    }
                },
                { from: 'server-ternationalization/*.json', to: PATH_ALT + '/resources/', force: true, cache: true, test: /\.json$/ },
                */
            ], { ignore: ['*.eslintrc'], copyUnmodified: false }
        )
    ]
};

module.exports = [ clientAndServerConfig ];

As you can see, all I do is move modified files and transform client files to remove require and use es6 imports.

Any ideas? I hope my recommendations were met.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.