diff --git a/package.json b/package.json index 7a775c3..210043a 100644 --- a/package.json +++ b/package.json @@ -49,6 +49,8 @@ "build:prod": "webpack --mode production", "clean": "rimraf .tmp && mkdirp .tmp/public", "lift": "sails lift", + "forever": "sudo NODE_ENV='production' ./node_modules/.bin/forever start app.js", + "stop": "./node_modules/.bin/forever stopall", "test": "npm run lint && npm run custom-tests && echo 'Done.'", "lint": "eslint . --max-warnings=0 --report-unused-disable-directives && echo '✔ Your .js files look good.'", "debug": "node --inspect app.js" diff --git a/webpack.config.js b/webpack.config.js index 4d357b2..232a891 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -1,41 +1,49 @@ const HtmlWebpackPlugin = require('html-webpack-plugin') const MiniCssExtractPlugin = require('mini-css-extract-plugin') +const webpack = require('webpack') const path = require('path') -module.exports = { - mode: process.env.NODE_ENV || 'development', - entry: { - login: './assets/js/login.js' - }, - output: { - path: path.join(__dirname, '/.tmp/public'), - filename: '[name].bundle.js' - }, - module: { - rules: [ - { - use: 'babel-loader', - test: /\.jsx?$/, - exclude: /node_modules/ - }, - { - test: /\.scss$/, - use: [ - process.env.NODE_ENV !== 'production' ? 'style-loader' : MiniCssExtractPlugin.loader, - 'css-loader', - 'sass-loader' - ] - } +module.exports = (env, argv) => { + const mode = argv.mode || 'development' + + return { + mode: mode || 'development', + entry: { + login: './assets/js/login.js' + }, + output: { + path: path.join(__dirname, '/.tmp/public'), + filename: '[name].bundle.js' + }, + module: { + rules: [ + { + use: 'babel-loader', + test: /\.jsx?$/, + exclude: /node_modules/ + }, + { + test: /\.scss$/, + use: [ + mode !== 'production' ? 'style-loader' : MiniCssExtractPlugin.loader, + 'css-loader', + 'sass-loader' + ] + } + ] + }, + plugins: [ + new HtmlWebpackPlugin({ + template: 'assets/templates/login.html', + links: mode === 'production' ? [{ rel: 'stylesheet', type: 'text/css', href: 'login.css' }] : [], + filename: path.join(__dirname, '/.tmp/public/login.html') + }), + new MiniCssExtractPlugin({ + filename: '[name].css' + }), + new webpack.DefinePlugin({ + 'process.env.NODE_ENV': JSON.stringify(mode) + }) ] - }, - plugins: [ - new HtmlWebpackPlugin({ - template: 'assets/templates/login.html', - links: process.env.NODE_ENV === 'production' ? [{ rel: 'stylesheet', type: 'text/css', href: 'login.css' }] : [], - filename: path.join(__dirname, '/.tmp/public/login.html') - }), - new MiniCssExtractPlugin({ - filename: '[name].css' - }) - ] + } }