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 50fb6bb59..c01d58f7a 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,8 @@ "docs:test": "docgen --source src --custom docs/index.yml --jsdoc jsdoc.json", "lint": "eslint src *.js", "lint:fix": "eslint --fix src", - "webpack": "parallel-webpack" + "build:browser": "webpack", + "prepublishOnly": "npm run test && npm run build:browser" }, "repository": { "type": "git", @@ -31,6 +32,7 @@ }, "homepage": "https://github.com/hydrabolt/discord.js#readme", "runkitExampleFilename": "./docs/examples/ping.js", + "unpkg": "./webpack/discord.min.js", "dependencies": { "long": "^3.0.0", "pako": "^1.0.0", @@ -55,7 +57,6 @@ "eslint": "^4.0.0", "jsdoc-strip-async-await": "^0.1.0", "json-filter-loader": "^1.0.0", - "parallel-webpack": "^2.0.0", "uglifyjs-webpack-plugin": "^1.0.0-beta.2", "webpack": "^3.0.0" }, diff --git a/travis/deploy.sh b/travis/deploy.sh index 340087312..774a9a19d 100644 --- a/travis/deploy.sh +++ b/travis/deploy.sh @@ -32,7 +32,7 @@ fi # Run the build npm run docs -VERSIONED=false npm run webpack +NODE_ENV=production npm run webpack if [ $DONT_COMMIT == true ]; then echo -e "\e[36m\e[1mNot commiting - exiting early" @@ -78,7 +78,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 d92cb7da2..2ccec7800 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -1,68 +1,60 @@ -/* - 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'], }, }, - ...require('snekfetch/webpack.supplemental').rules, - ], - }, - node: { - fs: 'empty', - dns: 'mock', - tls: 'mock', - child_process: 'empty', - dgram: 'empty', - __dirname: true, - process: false, - path: 'empty', - Buffer: false, - zlib: 'empty', - }, - plugins, - }; + }, + ...require('snekfetch/webpack.supplemental').rules, + ], + }, + 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);