From 7953ee7238dbddbbdcef3d42cdc495f09ece64b7 Mon Sep 17 00:00:00 2001 From: Jesper Hasselquist Date: Fri, 18 Oct 2019 09:58:43 +0200 Subject: [PATCH] Transpile and build one distributable Add webpack and babel to transpile and build into one distributable file. This also minifies the bundle. --- .babelrc | 3 +++ .gitignore | 3 +++ .npmignore | 1 + package.json | 16 ++++++++++++---- emojilib.json => src/emojilib.json | 0 index.js => src/index.js | 0 webpack.config.js | 23 +++++++++++++++++++++++ 7 files changed, 42 insertions(+), 4 deletions(-) create mode 100644 .babelrc rename emojilib.json => src/emojilib.json (100%) rename index.js => src/index.js (100%) create mode 100644 webpack.config.js diff --git a/.babelrc b/.babelrc new file mode 100644 index 0000000..69fe715 --- /dev/null +++ b/.babelrc @@ -0,0 +1,3 @@ +{ + "presets": ["@babel/preset-env"] +} diff --git a/.gitignore b/.gitignore index 2e4f3b3..fbbd5c0 100644 --- a/.gitignore +++ b/.gitignore @@ -86,6 +86,9 @@ public/ # vuepress build output .vuepress/dist +# webpack build output +dist/ + # Serverless directories .serverless/ diff --git a/.npmignore b/.npmignore index e8913bf..c942f92 100644 --- a/.npmignore +++ b/.npmignore @@ -2,3 +2,4 @@ test .editorconfig munci.png build +src diff --git a/package.json b/package.json index 07e0aa0..ed242b2 100644 --- a/package.json +++ b/package.json @@ -2,23 +2,31 @@ "name": "@baethon/munci", "version": "1.0.0", "description": "Convert string to emoji face", - "main": "index.js", + "main": "dist/index.js", "author": "Radoslaw Mejer ", "license": "MIT", "scripts": { "lint": "standard", "lint:fix": "standard --fix", - "build": "node build > emojilib.json", + "build": "webpack -p", + "build:emojilib": "node build > emojilib.json", "build:test-suite": "node build/testSuite > test/test_suite.json", + "prepublish": "npm run build", "test": "mocha" }, "devDependencies": { + "@babel/core": "^7.6.4", + "@babel/preset-env": "^7.6.3", + "babel-loader": "^8.0.6", "chai": "^4.2.0", "emoji-regex": "^8.0.0", "emojilib": "^2.4.0", "faker": "^4.1.0", "mocha": "^6.2.1", "skin-tone": "^2.0.0", - "standard": "^14.3.1" - } + "standard": "^14.3.1", + "webpack": "^4.41.2", + "webpack-cli": "^3.3.9" + }, + "dependencies": {} } diff --git a/emojilib.json b/src/emojilib.json similarity index 100% rename from emojilib.json rename to src/emojilib.json diff --git a/index.js b/src/index.js similarity index 100% rename from index.js rename to src/index.js diff --git a/webpack.config.js b/webpack.config.js new file mode 100644 index 0000000..90583d7 --- /dev/null +++ b/webpack.config.js @@ -0,0 +1,23 @@ +const path = require("path"); + +module.exports = () => { + return { + entry: { + index: path.join(__dirname, "src/index.js") + }, + output: { + filename: "[name].js", + path: path.join(__dirname, "dist") + }, + module: { + rules: [ + { + test: /\.js$/, + loader: "babel-loader", + exclude: /node_modules/ + } + ] + }, + }; +}; +