diff --git a/src/Squidex/Startup.cs b/src/Squidex/Startup.cs index df05ccd37..55e56f5fe 100644 --- a/src/Squidex/Startup.cs +++ b/src/Squidex/Startup.cs @@ -8,6 +8,7 @@ using System; using System.IO; +using System.Linq; using Autofac; using Autofac.Extensions.DependencyInjection; using Microsoft.AspNetCore.Builder; @@ -16,14 +17,14 @@ using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; +using Microsoft.Net.Http.Headers; using Squidex.Configurations; using Squidex.Configurations.Domain; using Squidex.Configurations.EventStore; using Squidex.Configurations.Identity; using Squidex.Configurations.Web; -using Squidex.Store.MongoDb; -using System.Linq; using Squidex.Pipeline; +using Squidex.Store.MongoDb; // ReSharper disable ConvertClosureToMethodGroup // ReSharper disable AccessToModifiedClosure @@ -175,7 +176,19 @@ namespace Squidex }); } - app.UseStaticFiles(); + app.UseStaticFiles(new StaticFileOptions + { + OnPrepareResponse = (context) => + { + var headers = context.Context.Response.GetTypedHeaders(); + + headers.CacheControl = new CacheControlHeaderValue + { + MaxAge = TimeSpan.FromDays(60), + + }; + } + }); } private static bool IsIdentityRequest(HttpContext context) diff --git a/src/Squidex/app-config/webpack.config.js b/src/Squidex/app-config/webpack.config.js index cf948977e..bcd85188c 100644 --- a/src/Squidex/app-config/webpack.config.js +++ b/src/Squidex/app-config/webpack.config.js @@ -50,7 +50,10 @@ module.exports = { test: /\.html$/, loader: 'html' }, { - test: /\.(png|jpe?g|gif|svg|woff|woff2|ttf|eot|ico)(\?.*$|$)/, + test: /\.(woff|woff2|ttf|eot)(\?.*$|$)/, + loader: 'file?name=assets/[name].[hash].[ext]' + }, { + test: /\.(png|jpe?g|gif|svg|ico)(\?.*$|$)/, loader: 'file?name=assets/[name].[hash].[ext]' }, { test: /\.css$/, @@ -72,12 +75,20 @@ module.exports = { * * See: https://github.com/wbuchwalter/tslint-loader */ - emitErrors: false, + emitErrors: true, /** * Share the configuration file with the IDE */ configuration: require('./../tslint.json') }, + htmlLoader: { + /** + * Define the root for images, so that we can use absolute urls + * + * See: https://github.com/webpack/html-loader#Advanced_Options + */ + root: helpers.root('app', 'images') + }, sassLoader: { includePaths: [helpers.root('app', 'theme')] }, diff --git a/src/Squidex/app-config/webpack.run.dev.js b/src/Squidex/app-config/webpack.run.dev.js index 370840172..585480ef6 100644 --- a/src/Squidex/app-config/webpack.run.dev.js +++ b/src/Squidex/app-config/webpack.run.dev.js @@ -15,6 +15,8 @@ module.exports = webpackMerge(runConfig, { */ devtool: 'cheap-module-eval-source-map', + //debug: true, + output: { filename: '[name].js', // Set the public path, because we are running the website from another port (5000) diff --git a/src/Squidex/app-config/webpack.run.prod.js b/src/Squidex/app-config/webpack.run.prod.js index fb847cc77..5b9a5bb4f 100644 --- a/src/Squidex/app-config/webpack.run.prod.js +++ b/src/Squidex/app-config/webpack.run.prod.js @@ -6,9 +6,7 @@ ExtractTextPlugin = require('extract-text-webpack-plugin'), const ENV = process.env.NODE_ENV = process.env.ENV = 'production'; -runConfig.plugins[0].options.options.tslint.emitErrors = true; - -module.exports = webpackMerge(runConfig, { +module.exports = webpackMerge.smart(runConfig, { devtool: 'source-map', output: { @@ -57,6 +55,9 @@ module.exports = webpackMerge(runConfig, { test: /\.scss$/, include: helpers.root('app', 'theme'), loader: ExtractTextPlugin.extract({ fallbackLoader: 'style', loader: 'css!sass?sourceMap' }) + }, { + test: /\.(png|jpe?g|gif|svg|ico)(\?.*$|$)/, + loaders: ['file?hash=sha512&digest=hex&name=[hash].[ext]', 'image-webpack?bypassOnDebug&optimizationLevel=7&interlaced=false'] } ] }, @@ -65,20 +66,17 @@ module.exports = webpackMerge(runConfig, { new webpack.NoErrorsPlugin(), new webpack.DefinePlugin({ 'process.env': { 'ENV': JSON.stringify(ENV) } }), + /* + * Puts each bundle into a file and appends the hash of the file to the path. + * + * See: https://github.com/webpack/extract-text-webpack-plugin + */ + new ExtractTextPlugin('[name].[hash].css'), + new webpack.optimize.UglifyJsPlugin({ mangle: { screw_ie8: true, keep_fnames: true } }), - - function () { - this.plugin('done', function (stats) { - if (stats.compilation.errors && stats.compilation.errors.length && process.argv.indexOf('--watch') == -1) { - console.log(stats.compilation.errors); - - throw new Error('webpack build failed.'); - } - }); - } ] }); \ No newline at end of file diff --git a/src/Squidex/app-config/webpack.test.coverage.js b/src/Squidex/app-config/webpack.test.coverage.js index e7e2d4de5..ea510d58b 100644 --- a/src/Squidex/app-config/webpack.test.coverage.js +++ b/src/Squidex/app-config/webpack.test.coverage.js @@ -4,7 +4,7 @@ var webpackMerge = require('webpack-merge'), helpers = require('./helpers'), testConfig = require('./webpack.test.js'); -testConfig.module.loaders.shift(); +removeTsLoader(); module.exports = webpackMerge(testConfig, { module: { @@ -23,4 +23,17 @@ module.exports = webpackMerge(testConfig, { } }); -console.log(JSON.stringify(module.exports, null, 4)); \ No newline at end of file +function removeTsLoader() { + var tsModuleIndex = -1; + + for (var i = 0, len = testConfig.module.loaders.length; i < len; i += 1) { + if (testConfig.module.loaders[i].test.source.indexOf('.ts') > 0) { + tsModuleIndex = i; + break; + } + } + + if (tsModuleIndex >= 0) { + testConfig.module.loaders.splice(tsModuleIndex, 1); + } +} \ No newline at end of file diff --git a/src/Squidex/app/app.component.html b/src/Squidex/app/app.component.html index 8012c5ac6..0b6ebed1f 100644 --- a/src/Squidex/app/app.component.html +++ b/src/Squidex/app/app.component.html @@ -1,7 +1,7 @@ 
- +
Loading awesomeness
diff --git a/src/Squidex/app/components/public/home-page.component.html b/src/Squidex/app/components/public/home-page.component.html index 2e769ac67..12604b098 100644 --- a/src/Squidex/app/components/public/home-page.component.html +++ b/src/Squidex/app/components/public/home-page.component.html @@ -1,5 +1,5 @@
- + diff --git a/src/Squidex/wwwroot/images/loader.gif b/src/Squidex/app/images/loader.gif similarity index 100% rename from src/Squidex/wwwroot/images/loader.gif rename to src/Squidex/app/images/loader.gif diff --git a/src/Squidex/wwwroot/images/logo.png b/src/Squidex/app/images/logo.png similarity index 100% rename from src/Squidex/wwwroot/images/logo.png rename to src/Squidex/app/images/logo.png diff --git a/src/Squidex/package.json b/src/Squidex/package.json index 8976930e6..ba83b0cf7 100644 --- a/src/Squidex/package.json +++ b/src/Squidex/package.json @@ -49,6 +49,7 @@ "font-awesome-sass-loader": "^1.0.1", "html-loader": "^0.4.3", "html-webpack-plugin": "^2.22.0", + "image-webpack-loader": "^3.0.0", "istanbul-instrumenter-loader": "^0.2.0", "jasmine-core": "^2.4.1", "karma": "^1.1.1", diff --git a/src/Squidex/wwwroot/index.html b/src/Squidex/wwwroot/index.html index b7d53ffbe..b35ff0ddf 100644 --- a/src/Squidex/wwwroot/index.html +++ b/src/Squidex/wwwroot/index.html @@ -36,7 +36,7 @@
- +
Loading awesomeness
diff --git a/src/Squidex/wwwroot/loader.gif b/src/Squidex/wwwroot/loader.gif new file mode 100644 index 000000000..0a8226a3b Binary files /dev/null and b/src/Squidex/wwwroot/loader.gif differ