mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
make webpack over 9000 times better (#1816)
* webpack stuff * even better * Update browser.js
This commit is contained in:
9
browser.js
Normal file
9
browser.js
Normal file
@@ -0,0 +1,9 @@
|
||||
const browser = typeof window !== 'undefined';
|
||||
const webpack = !!process.env.__DISCORD_WEBPACK__;
|
||||
|
||||
const Discord = require('./');
|
||||
|
||||
module.exports = Discord;
|
||||
if (browser && webpack) window.Discord = Discord; // eslint-disable-line no-undef
|
||||
// eslint-disable-next-line no-console
|
||||
else if (!browser) console.warn('Warning: Attempting to use browser version of Discord.js in a non-browser environment!');
|
||||
@@ -1,5 +1,4 @@
|
||||
const os = require('os');
|
||||
const EventEmitter = require('events').EventEmitter;
|
||||
const EventEmitter = require('events');
|
||||
const Constants = require('../util/Constants');
|
||||
const Permissions = require('../util/Permissions');
|
||||
const Util = require('../util/Util');
|
||||
@@ -250,7 +249,7 @@ class Client extends EventEmitter {
|
||||
* @readonly
|
||||
*/
|
||||
get browser() {
|
||||
return os.platform() === 'browser';
|
||||
return typeof window !== 'undefined';
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
const browser = require('os').platform() === 'browser';
|
||||
const browser = typeof window !== 'undefined';
|
||||
const EventEmitter = require('events');
|
||||
const Constants = require('../../util/Constants');
|
||||
const zlib = require('zlib');
|
||||
|
||||
@@ -61,5 +61,3 @@ module.exports = {
|
||||
VoiceChannel: require('./structures/VoiceChannel'),
|
||||
Webhook: require('./structures/Webhook'),
|
||||
};
|
||||
|
||||
if (require('os').platform() === 'browser') window.Discord = module.exports; // eslint-disable-line no-undef
|
||||
|
||||
@@ -12,6 +12,11 @@ const createConfig = options => {
|
||||
const plugins = [
|
||||
new webpack.DefinePlugin({ 'global.GENTLY': false }),
|
||||
new webpack.optimize.ModuleConcatenationPlugin(),
|
||||
new webpack.DefinePlugin({
|
||||
'process.env': {
|
||||
__DISCORD_WEBPACK__: '"true"',
|
||||
},
|
||||
}),
|
||||
];
|
||||
|
||||
if (options.minify) plugins.push(new UglifyJSPlugin({ uglifyOptions: { output: { comments: false } } }));
|
||||
@@ -19,7 +24,7 @@ const createConfig = options => {
|
||||
const filename = `./webpack/discord${process.env.VERSIONED === 'false' ? '' : '.' + version}${options.minify ? '.min' : ''}.js`; // eslint-disable-line
|
||||
|
||||
return {
|
||||
entry: './src/index.js',
|
||||
entry: './browser.js',
|
||||
output: {
|
||||
path: __dirname,
|
||||
filename,
|
||||
|
||||
Reference in New Issue
Block a user