diff --git a/.npmignore b/.npmignore index 86270540e..0ad23d8df 100644 --- a/.npmignore +++ b/.npmignore @@ -14,8 +14,6 @@ deploy/ .vscode/ docs/ -webpack/ - # NPM ignore .eslintrc.json .gitattributes diff --git a/package.json b/package.json index c57662825..0eb2aa7a8 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,8 @@ "docs:test": "docgen --source src --custom docs/index.yml", "lint": "eslint src *.js", "lint:fix": "eslint --fix src", - "webpack": "parallel-webpack" + "build:browser": "webpack", + "prepublishOnly": "npm run test && NODE_ENV=production npm run build:browser" }, "repository": { "type": "git", @@ -31,6 +32,7 @@ }, "homepage": "https://github.com/discordjs/discord.js#readme", "runkitExampleFilename": "./docs/examples/ping.js", + "unpkg": "./webpack/discord.min.js", "dependencies": { "pako": "^1.0.0", "prism-media": "hydrabolt/prism-media", @@ -51,7 +53,6 @@ "discord.js-docgen": "discordjs/docgen", "eslint": "^4.17.0", "json-filter-loader": "^1.0.0", - "parallel-webpack": "^2.2.0", "uglifyjs-webpack-plugin": "^1.1.8", "webpack": "^3.11.0" }, diff --git a/travis/deploy.sh b/travis/deploy.sh index ab6116008..d7fbe8b87 100644 --- a/travis/deploy.sh +++ b/travis/deploy.sh @@ -26,7 +26,7 @@ fi # Run the build npm run docs -VERSIONED=false npm run webpack +NODE_ENV=production npm run build:browser if [ $DONT_COMMIT == true ]; then echo -e "\e[36m\e[1mNot commiting - exiting early" @@ -72,7 +72,6 @@ TARGET_BRANCH="webpack" git clone $REPO out -b $TARGET_BRANCH # Move the generated webpack over -mv webpack/discord.js out/discord.$SOURCE.js mv webpack/discord.min.js out/discord.$SOURCE.min.js # Commit and push diff --git a/webpack.config.js b/webpack.config.js index f5d0050f1..ef4ad0084 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -1,67 +1,59 @@ -/* - ONLY RUN BUILDS WITH `npm run webpack`! - DO NOT USE NORMAL WEBPACK! IT WILL NOT WORK! -*/ - const path = require('path'); const webpack = require('webpack'); -const createVariants = require('parallel-webpack').createVariants; const UglifyJSPlugin = require('uglifyjs-webpack-plugin'); const version = require('./package.json').version; -const createConfig = options => { - const plugins = [ - new webpack.optimize.ModuleConcatenationPlugin(), - ]; +const plugins = [ + new webpack.optimize.ModuleConcatenationPlugin(), +]; - if (options.minify) { - plugins.push(new UglifyJSPlugin({ - uglifyOptions: { - mangle: { keep_classnames: true }, - output: { comments: false }, - }, - })); - } +const prod = process.env.NODE_ENV === 'production'; - // eslint-disable-next-line max-len - const filename = `discord${process.env.VERSIONED === 'false' ? '' : `.${version}`}${options.minify ? '.min' : ''}.js`; - - return { - entry: './src/index.js', - output: { - path: path.resolve('./webpack'), - filename, - library: 'Discord', - libraryTarget: 'window', +if (prod) { + plugins.push(new UglifyJSPlugin({ + uglifyOptions: { + mangle: { keep_classnames: true }, + output: { comments: false }, }, - module: { - rules: [ - { test: /\.md$/, loader: 'ignore-loader' }, - { - test: require.resolve('./package.json'), - use: { - loader: 'json-filter-loader', - options: { - used: ['version', 'homepage'], - }, + })); +} + +// eslint-disable-next-line max-len +const filename = `discord${process.env.VERSIONED ? `.${version}` : ''}${prod ? '.min' : ''}.js`; + +module.exports = { + entry: './src/index.js', + output: { + path: path.resolve('./webpack'), + filename, + library: 'Discord', + libraryTarget: 'umd', + }, + module: { + rules: [ + { test: /\.md$/, loader: 'ignore-loader' }, + { + test: require.resolve('./package.json'), + use: { + loader: 'json-filter-loader', + options: { + used: ['version', 'homepage'], }, }, - ], - }, - node: { - fs: 'empty', - dns: 'mock', - tls: 'mock', - child_process: 'empty', - dgram: 'empty', - __dirname: true, - process: false, - path: 'empty', - Buffer: false, - zlib: 'empty', - }, - plugins, - }; + }, + ], + }, + node: { + fs: 'empty', + dns: 'mock', + tls: 'mock', + child_process: 'empty', + dgram: 'empty', + __dirname: true, + process: false, + path: 'empty', + Buffer: false, + zlib: 'empty', + }, + plugins, }; - -module.exports = createVariants({}, { minify: [false, true] }, createConfig);