diff --git a/.babelrc b/.babelrc new file mode 100644 index 00000000..8a87b4dc --- /dev/null +++ b/.babelrc @@ -0,0 +1,3 @@ +{ + "presets": ["es2015"] +} \ No newline at end of file diff --git a/.gitignore b/.gitignore index 6a48e0fb..9815ae84 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,4 @@ node_modules *.log .DS_Store -.idea +build diff --git a/config/webpack.config.js b/config/webpack.config.js new file mode 100644 index 00000000..aac59106 --- /dev/null +++ b/config/webpack.config.js @@ -0,0 +1,43 @@ +const webpack = require("webpack"); +const path = require("path"); +const BabiliPlugin = require("babili-webpack-plugin"); +const CleanWebpackPlugin = require("clean-webpack-plugin"); + +module.exports = { + entry: path.resolve(__dirname, "../index.js"), + output: { + path: path.resolve(__dirname, "../build"), + filename: "mathsteps.min.js", + libraryTarget: "umd", + library: "mathsteps" + }, + externals: { + mathjs: "mathjs" + }, + module: { + rules: [ + { + test: /\.js$/, + exclude: [/node_modules/, /scripts/, /test/, /Config/], + use: ["babel-loader"] + } + ] + }, + plugins: [ + new webpack.LoaderOptionsPlugin({ // Options for loader that will run on files + minimize: true, + debug: false, + options: { + context: __dirname + } + }), + new webpack.optimize.ModuleConcatenationPlugin(), // Webpack 3 (scope hoisting) + new webpack.optimize.UglifyJsPlugin(), // Minifier + new webpack.DefinePlugin({ // Production ready build + "process.env": { + NODE_ENV: JSON.stringify("production") + } + }), + new CleanWebpackPlugin([path.resolve(__dirname, "../build")]) // Prebuild (kinda hook) + ] +}; \ No newline at end of file diff --git a/package.json b/package.json index d54df282..18dc9fe4 100644 --- a/package.json +++ b/package.json @@ -2,23 +2,34 @@ "name": "mathsteps", "version": "0.1.6", "description": "Step by step math solutions", - "main": "index.js", + "main": "./build/mathsteps.min.js", "dependencies": { "mathjs": "3.11.2" }, "engines": { "node": ">=6.0.0" }, + "files": [ + "build" + ], "devDependencies": { + "babel-core": "^6.25.0", + "babel-loader": "^7.1.1", + "babel-preset-es2015": "^6.24.1", + "babili-webpack-plugin": "^0.1.2", + "clean-webpack-plugin": "^0.1.16", "eslint": "^3.10.2", "eslint-config-google": "^0.7.0", "eslint-plugin-sort-requires": "^2.1.0", - "mocha": "2.4.5" + "mocha": "2.4.5", + "webpack": "^3.0.0" }, "scripts": { - "lint": "node_modules/.bin/eslint .", - "test": "node_modules/.bin/mocha --recursive", - "setup-hooks": "ln -s ../../scripts/git-hooks/pre-commit.sh .git/hooks/pre-commit" + "build": "NODE_ENV=production ./node_modules/.bin/webpack --config ./config/webpack.config.js --display-max-modules 0", + "lint": "node_modules/.bin/eslint ./lib", + "prebuild": "rm -rf ./build", + "setup-hooks": "ln -s ../../scripts/git-hooks/pre-commit.sh .git/hooks/pre-commit", + "test": "node_modules/.bin/mocha --recursive" }, "repository": { "type": "git",