diff --git a/bin/dev.js b/bin/dev.js index a9b224d64..ae1a2d243 100644 --- a/bin/dev.js +++ b/bin/dev.js @@ -2,7 +2,7 @@ import Express from 'express'; import webpack from 'webpack'; import WebpackDevServer from 'webpack-dev-server'; import path from 'path'; -import config from '../config/webpack.config'; +import config from '../config/webpack.config-dev'; import colors from 'colors'; import remotedev from 'remotedev-server'; diff --git a/config/webpack.config-dev.js b/config/webpack.config-dev.js new file mode 100644 index 000000000..890fb04a3 --- /dev/null +++ b/config/webpack.config-dev.js @@ -0,0 +1,79 @@ +const path = require('path'); +const webpack = require('webpack'); +const ExtractTextPlugin = require('extract-text-webpack-plugin'); +const GitRevisionPlugin = require('git-revision-webpack-plugin'); + +// load variables from .env +require('dotenv').config(); + +// fix Widnows 10 Ubuntu issues with less loader: +try { + require('os').networkInterfaces(); +} catch (e) { + require('os').networkInterfaces = () => ({}); +} + +const extractCss = new ExtractTextPlugin('style.css'); +const gitRevisionPlugin = new GitRevisionPlugin({ + versionCommand: 'describe --always --tags' +}); + +module.exports = { + devtool: process.env.NODE_ENV === 'development' ? 'source-map' : 'none', + entry: path.join(__dirname, '..', 'src/client.js'), + output: { + filename: 'bundle.js', + path: path.join(__dirname, '..', 'public'), + publicPath: '/public/' + }, + resolve: { + alias: { + moment: 'moment/moment.js' + } + }, + module: { + loaders: [ + { test: /\.jsx?$/, exclude: /node_modules/, loaders: ['babel-loader'] }, + { test: /\.json$/, loader: 'json-loader' }, + { + test: /\.css$/, + loader: extractCss.extract(['css-loader']) + }, + { + test: /\.less$/, + loader: extractCss.extract(['css-loader?modules', 'less-loader']) + }, + { + test: /\.scss$/, + loader: extractCss.extract(['css-loader?modules', 'sass-loader']) + }, + { + test: /.*\.(gif|png|jpe?g|svg)$/i, + loaders: ['file-loader'] + } + ] + }, + plugins: [ + extractCss, + new webpack.DefinePlugin({ + 'process.env': { + NODE_ENV: "'" + process.env.NODE_ENV + "'", + API_BASE: "'" + process.env.API_BASE + "'", + TITLE: "'" + process.env.TITLE + "'", + REDUX_DEV_SERVER_PORT: "'" + process.env.REDUX_DEV_SERVER_PORT + "'", + ALLOW_NORMAL_REGISTRATION: + "'" + process.env.ALLOW_NORMAL_REGISTRATION + "'", + ALLOW_LDAP_REGISTRATION: + "'" + process.env.ALLOW_LDAP_REGISTRATION + "'", + ALLOW_CAS_REGISTRATION: "'" + process.env.ALLOW_CAS_REGISTRATION + "'", + LOGGER_MIDDLEWARE_VERBOSE: "'" + process.env.LOGGER_MIDDLEWARE_VERBOSE + "'", + LOGGER_MIDDLEWARE_EXCEPTIONS: "'" + process.env.LOGGER_MIDDLEWARE_EXCEPTIONS + "'", + }, + gitRevision: { + VERSION: JSON.stringify(gitRevisionPlugin.version()), + COMMITHASH: JSON.stringify(gitRevisionPlugin.commithash()), + BRANCH: JSON.stringify(gitRevisionPlugin.branch()) + } + }) + ] +}; diff --git a/config/webpack.config.js b/config/webpack.config.js index 890fb04a3..09dbb1074 100644 --- a/config/webpack.config.js +++ b/config/webpack.config.js @@ -13,7 +13,7 @@ try { require('os').networkInterfaces = () => ({}); } -const extractCss = new ExtractTextPlugin('style.css'); +const extractCss = new ExtractTextPlugin('style-[contenthash].css'); const gitRevisionPlugin = new GitRevisionPlugin({ versionCommand: 'describe --always --tags' }); @@ -22,7 +22,7 @@ module.exports = { devtool: process.env.NODE_ENV === 'development' ? 'source-map' : 'none', entry: path.join(__dirname, '..', 'src/client.js'), output: { - filename: 'bundle.js', + filename: 'bundle-[hash].js', path: path.join(__dirname, '..', 'public'), publicPath: '/public/' }, diff --git a/package.json b/package.json index 403dad055..d1395ce80 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ }, "private": true, "scripts": { - "clean": "rm -f public/bundle.js && rm -f public/bundle.js.min && rm -f bin/server.js", + "clean": "rm -f public/bundle-* && rm -f public/style-* && rm -f bin/server.js", "build:server": "webpack -p --config config/webpack.server.js", "build:client": "webpack -p --config config/webpack.config.js", "build:server:test": "webpack --config config/webpack.server.js", @@ -47,6 +47,7 @@ "file-saver": "^1.3.3", "flat": "^4.0.0", "flow-bin": "^0.46.0", + "glob": "^7.1.2", "global": "^4.3.1", "immutable": "^3.8.1", "isomorphic-fetch": "^2.2.1", diff --git a/public/public/term_cyr.ttf b/public/public/term_cyr.ttf new file mode 100644 index 000000000..8b9f399dc Binary files /dev/null and b/public/public/term_cyr.ttf differ diff --git a/public/style.css.map b/public/style.css.map deleted file mode 100644 index f95a8806b..000000000 --- a/public/style.css.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"sources":[],"names":[],"mappings":"","file":"style.css","sourceRoot":""} \ No newline at end of file diff --git a/src/server.js b/src/server.js index 80ac1db42..075061b4f 100644 --- a/src/server.js +++ b/src/server.js @@ -41,11 +41,29 @@ if (typeof atob === 'undefined') { * some basic middleware for tempaltes and static file serving. */ -const bundle = process.env.BUNDLE || '/bundle.js'; +function getFileName(pattern, addPrefix = '') { + const glob = require('glob'); + const files = glob.sync(pattern); + if (!files || files.length < 1) { + return null; + } + const fileName = files[0].substr(files[0].lastIndexOf('/') + 1); + return fileName ? addPrefix + fileName : null; +} + +const bundle = + process.env.BUNDLE || getFileName('public/bundle-*.js', '/') || '/bundle.js'; +const style = getFileName('public/style-*.css', '/') || '/style.css'; let app = new Express(); app.set('view engine', 'ejs'); -app.use(Express.static('public')); +app.use( + Express.static('public', { + immutable: true, + maxAge: '30d', + lastModified: true + }) +); app.use(cookieParser()); const renderWithoutSSR = (res, renderProps) => { @@ -55,7 +73,7 @@ const renderWithoutSSR = (res, renderProps) => { head, reduxState: 'undefined', bundle, - style: '/style.css' + style }); }; @@ -73,7 +91,7 @@ const renderPage = (res, store, renderProps) => { head, reduxState, bundle, - style: '/style.css' + style }); }; diff --git a/views/index.ejs b/views/index.ejs index 4fc533074..6a8584215 100644 --- a/views/index.ejs +++ b/views/index.ejs @@ -8,6 +8,41 @@ <%- head.link.toString() %> + @@ -15,16 +50,27 @@ - + +
Loading...
+
<%- html %>
<% if (reduxState) { %> - <% } %> - + <% } %> + + + + + diff --git a/yarn.lock b/yarn.lock index fcecacb76..e58be7bb0 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3201,7 +3201,7 @@ glob@^5.0.3: once "^1.3.0" path-is-absolute "^1.0.0" -glob@^7.0.0, glob@^7.0.3, glob@^7.0.5, glob@~7.1.1: +glob@^7.0.0, glob@^7.0.3, glob@^7.0.5, glob@^7.1.2, glob@~7.1.1: version "7.1.2" resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.2.tgz#c19c9df9a028702d678612384a6552404c636d15" dependencies: