From 5c684ef0688c7551f886829636fd97a854b3df9d Mon Sep 17 00:00:00 2001 From: Hermann Blum <hermannsblum@yahoo.de> Date: Thu, 30 Nov 2017 14:15:04 +0100 Subject: [PATCH] add webpack and node structure --- .eslintrc.js | 15 +++++++++++ package.json | 37 ++++++++++++++++++++++++++ webpack.config.js | 60 ++++++++++++++++++++++++++++++++++++++++++ webpack.config.prod.js | 24 +++++++++++++++++ 4 files changed, 136 insertions(+) create mode 100644 .eslintrc.js create mode 100644 package.json create mode 100644 webpack.config.js create mode 100644 webpack.config.prod.js diff --git a/.eslintrc.js b/.eslintrc.js new file mode 100644 index 0000000..706e695 --- /dev/null +++ b/.eslintrc.js @@ -0,0 +1,15 @@ +module.exports = { + "extends": "airbnb-base", + "plugins": [ + "import" + ], + "env": { + "browser": true, + }, + "rules": { + "no-console": 0, + "class-methods-use-this": 0, + "prefer-destructuring": 1, + "no-underscore-dangle": 0, + } +}; diff --git a/package.json b/package.json new file mode 100644 index 0000000..0f44a9e --- /dev/null +++ b/package.json @@ -0,0 +1,37 @@ +{ + "name": "amiv-admintools", + "version": "0.0.1", + "description": "Admintools to access the AMIV API.", + "main": "index.js", + "scripts": { + "start": "webpack-dev-server --hot --inline", + "build": "webpack -p --config webpack.config.prod.js", + "lint": "eslint src/**" + }, + "repository": { + "type": "git", + "url": "git@gitlab.ethz.ch:amiv/amiv-admintool.git" + }, + "author": "Hermann Blum et al", + "dependencies": { + "ajv": "^5.5.0", + "axios": "^0.17.1", + "babel": "^6.23.0", + "babel-core": "^6.26.0", + "babel-loader": "^7.1.2", + "babel-preset-env": "^1.6.1", + "compression-webpack-plugin": "^1.0.1", + "file-loader": "^1.1.5", + "mithril": "^1.1.5", + "querystring": "^0.2.0", + "uglifyjs-webpack-plugin": "^1.0.1", + "webpack": "^3.8.1" + }, + "devDependencies": { + "eslint": "^4.10.0", + "eslint-config-airbnb-base": "^12.1.0", + "eslint-loader": "^1.9.0", + "eslint-plugin-import": "^2.8.0", + "webpack-dev-server": "^2.9.3" + } +} diff --git a/webpack.config.js b/webpack.config.js new file mode 100644 index 0000000..6bd7e38 --- /dev/null +++ b/webpack.config.js @@ -0,0 +1,60 @@ +const publicPath = '/dist'; + +const config = { + context: `${__dirname}/src`, // `__dirname` is root of project + + entry: './index.js', + + output: { + path: `${__dirname}/dist`, // `dist` is the destination + filename: 'bundle.js', + }, + + // To run development server + devServer: { + contentBase: __dirname, + publicPath, + compress: true, + port: 9000, + hot: true, + index: 'index.html', + }, + + module: { + rules: [ + { + test: /\.js$/, + enforce: "pre", + exclude: /node_modules/, + loader: 'eslint-loader', + options: { + emitWarning: true // don't fail the build for linting errors + } + }, + { + test: /\.js$/, // Check for all js files + exclude: /node_modules/, + use: [{ + loader: 'babel-loader', + options: { presets: ['env'] }, + }], + }, + { + test: /\.(png|jpe?g|gif|svg)$/, + use: [ + { + loader: 'file-loader', + options: { + publicPath, + }, + }, + ], + }, + ], + + }, + + devtool: 'eval-source-map', // Default development sourcemap +}; + +module.exports = config; diff --git a/webpack.config.prod.js b/webpack.config.prod.js new file mode 100644 index 0000000..3017e2f --- /dev/null +++ b/webpack.config.prod.js @@ -0,0 +1,24 @@ +const webpack = require('webpack'); +const CompressionPlugin = require('compression-webpack-plugin'); + +// Start with dev config +const config = require('./webpack.config.js'); + +// Remove development server and code map +config.devServer = undefined; +config.devtool = ''; + +// Add optimization plugins +config.plugins = [ + new webpack.optimize.UglifyJsPlugin(), + new webpack.optimize.AggressiveMergingPlugin(), + new CompressionPlugin({ + asset: '[path].gz[query]', + algorithm: 'gzip', + test: /\.js$|\.css$|\.html$/, + threshold: 10240, + minRatio: 0.8, + }), +]; + +module.exports = config; -- GitLab