var path = require('path'); var webpack = require('webpack'); var HtmlWebpackPlugin = require('html-webpack-plugin'); var CopyWebpackPlugin = require('copy-webpack-plugin'); var { CleanWebpackPlugin } = require('clean-webpack-plugin'); var definePlugin = new webpack.DefinePlugin({ 'process.env.DEV': JSON.stringify(JSON.parse(process.env.DEV || 'false')) }); var outpath = './webpack/'; if (!process.env.DEV || process.env.DEV === false) { console.log('CORDOVA environment'); outpath = 'www/'; } else { console.log('DEV environment'); } // optimization: { // splitChunks: { // chunks: 'all', // }, // }, module.exports = { devtool: 'cheap-source-map', mode: 'development', target: 'web', entry: { app: path.resolve(__dirname, 'src/main.js') // socketio: path.resolve(__dirname, 'node_modules/socket.io-client/dist/socket.io.slim'), // phaser: 'phaser' }, output: { filename: 'app.bundle.js', path: path.resolve(__dirname, outpath + 'dist') }, plugins: [ definePlugin, new CleanWebpackPlugin(), new CopyWebpackPlugin([ { context: path.resolve(__dirname, 'src', 'assets'), from: '**/*', to: path.resolve(__dirname, outpath, 'assets') } ]), new HtmlWebpackPlugin({ filename: '../index.html', template: './src/index.html', minify: { removeAttributeQuotes: false, collapseWhitespace: false, html5: false, minifyCSS: false, minifyJS: false, minifyURLs: false, removeComments: false, removeEmptyAttributes: false }, hash: false, inject: true }), new webpack.DefinePlugin({ CANVAS_RENDERER: JSON.stringify(true), WEBGL_RENDERER: JSON.stringify(true) }) ], module: { rules: [ { test: /\.js$/, exclude: /(node_modules|server)/, loaders: "babel-loader" }, { test: /\.(gif|png|jpe?g|svg|xml)$/i, use: "file-loader" }, { test: [/\.vert$/, /\.frag$/], use: "raw-loader" } ] } };