From 35d9640b856b5ce1bc2bb27d71d155659aed4b70 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Sun, 2 Jun 2019 11:11:44 +0200 Subject: [PATCH] Simplified build --- src/Squidex/.vscode/settings.json | 36 -- src/Squidex/app-config/helpers.js | 25 - src/Squidex/app-config/karma-test-shim.js | 3 +- src/Squidex/app-config/karma.conf.js | 6 +- src/Squidex/app-config/karma.coverage.conf.js | 6 +- src/Squidex/app-config/webpack.config.js | 446 +++++++++++++----- src/Squidex/app-config/webpack.run.base.js | 35 -- src/Squidex/app-config/webpack.run.dev.js | 68 --- src/Squidex/app-config/webpack.run.prod.js | 137 ------ .../app-config/webpack.test.coverage.js | 37 -- src/Squidex/app-config/webpack.test.js | 16 - .../app/shared/state/assets.state.spec.ts | 31 +- src/Squidex/app/shims.ts | 2 - src/Squidex/package-lock.json | 78 +-- src/Squidex/package.json | 13 +- 15 files changed, 377 insertions(+), 562 deletions(-) delete mode 100644 src/Squidex/.vscode/settings.json delete mode 100644 src/Squidex/app-config/helpers.js delete mode 100644 src/Squidex/app-config/webpack.run.base.js delete mode 100644 src/Squidex/app-config/webpack.run.dev.js delete mode 100644 src/Squidex/app-config/webpack.run.prod.js delete mode 100644 src/Squidex/app-config/webpack.test.coverage.js delete mode 100644 src/Squidex/app-config/webpack.test.js diff --git a/src/Squidex/.vscode/settings.json b/src/Squidex/.vscode/settings.json deleted file mode 100644 index 26a63fc30..000000000 --- a/src/Squidex/.vscode/settings.json +++ /dev/null @@ -1,36 +0,0 @@ -{ - // When opening a file, `editor.tabSize` and `editor.insertSpaces` will be detected based on the file contents. - "editor.detectIndentation": false, - - // Typescript version from local package to be consistent - "typescript.tsdk": "node_modules/typescript/lib", - - // Configure glob patterns for excluding files and folders. - "files.exclude": { - "**/node_modules": true, - "**/Assets": true, - "**/artifacts": true, - "**/build": true, - "**/logs": true, - "**/out": true, - "**/obj": true, - "**/bin": true, - "**/*.lock.json": true, - "**/*.bat": true, - "**/*.sln": true, - "**/*.sln.DotSettings": true, - "**/*.user": true, - "**/*.xproj": true, - "**/*.gitattributes": true, - "appsetttings.Development.json": true, - "appsetttings.Production.json": true, - ".awcache": true, - ".vs:": true, - ".vscode:": true - }, - - "coverage-gutters.coverageFileNames": [ - "_test-output/coverage/lcov.info" - ], - "coverage-gutters.showLineCoverage": true -} \ No newline at end of file diff --git a/src/Squidex/app-config/helpers.js b/src/Squidex/app-config/helpers.js deleted file mode 100644 index acae3e4bb..000000000 --- a/src/Squidex/app-config/helpers.js +++ /dev/null @@ -1,25 +0,0 @@ -var path = require('path'); - -var appRoot = path.resolve(__dirname, '..'); - -exports.root = function () { - var newArgs = Array.prototype.slice.call(arguments, 0); - - return path.join.apply(path, [appRoot].concat(newArgs)); -}; - -exports.removeLoaders = function (config, extensions) { - var rules = config.module.rules; - - for (var i = 0; i < rules.length; i += 1) { - var rule = rules[i]; - - for (var j = 0; j < extensions.length; j += 1) { - if (rule.test.source.indexOf(extensions[j]) >= 0) { - rules.splice(i, 1); - i--; - break; - } - } - } -} \ No newline at end of file diff --git a/src/Squidex/app-config/karma-test-shim.js b/src/Squidex/app-config/karma-test-shim.js index 41a41e554..773d09e87 100644 --- a/src/Squidex/app-config/karma-test-shim.js +++ b/src/Squidex/app-config/karma-test-shim.js @@ -1,7 +1,6 @@ Error.stackTraceLimit = Infinity; -require('core-js/es6'); -require('core-js/es7/reflect'); +require('core-js/proposals/reflect-metadata'); require('zone.js/dist/zone'); require('zone.js/dist/long-stack-trace-zone'); diff --git a/src/Squidex/app-config/karma.conf.js b/src/Squidex/app-config/karma.conf.js index 8b64456f4..f4776e18a 100644 --- a/src/Squidex/app-config/karma.conf.js +++ b/src/Squidex/app-config/karma.conf.js @@ -1,4 +1,4 @@ -var webpackConfig = require('./webpack.test'); +const webpackConfig = require('./webpack.config'); module.exports = function (config) { var _config = { @@ -10,7 +10,7 @@ module.exports = function (config) { frameworks: ['jasmine'], /** - * Load additional test shim to setup angular2 for testing. + * Load additional test shim to setup angular for testing. */ files: [ { pattern: './app-config/karma-test-shim.js', watched: false } @@ -23,7 +23,7 @@ module.exports = function (config) { /** * Load the files with webpack and use test configuration for it. */ - webpack: webpackConfig, + webpack: webpackConfig({ target: 'tests', jit: true }), webpackMiddleware: { stats: 'errors-only' diff --git a/src/Squidex/app-config/karma.coverage.conf.js b/src/Squidex/app-config/karma.coverage.conf.js index 441b998b9..8a9b849bf 100644 --- a/src/Squidex/app-config/karma.coverage.conf.js +++ b/src/Squidex/app-config/karma.coverage.conf.js @@ -1,4 +1,4 @@ -var webpackConfig = require('./webpack.test.coverage'); +const webpackConfig = require('./webpack.config'); module.exports = function (config) { var _config = { @@ -10,7 +10,7 @@ module.exports = function (config) { frameworks: ['jasmine'], /** - * Load additional test shim to setup angular2 for testing. + * Load additional test shim to setup angular for testing. */ files: [ { pattern: './app-config/karma-test-shim.js', watched: false } @@ -23,7 +23,7 @@ module.exports = function (config) { /** * Load the files with webpack and use test configuration for it. */ - webpack: webpackConfig, + webpack: webpackConfig({ target: 'tests', coverage: true, jit: true }), webpackMiddleware: { stats: 'errors-only' diff --git a/src/Squidex/app-config/webpack.config.js b/src/Squidex/app-config/webpack.config.js index 5ff10d725..edaeaa5a8 100644 --- a/src/Squidex/app-config/webpack.config.js +++ b/src/Squidex/app-config/webpack.config.js @@ -1,6 +1,13 @@ const webpack = require('webpack'), - path = require('path'), - helpers = require('./helpers'); + path = require('path'); + +const appRoot = path.resolve(__dirname, '..'); + +function root() { + var newArgs = Array.prototype.slice.call(arguments, 0); + + return path.join.apply(path, [appRoot].concat(newArgs)); +}; const plugins = { // https://github.com/webpack-contrib/mini-css-extract-plugin @@ -8,147 +15,356 @@ const plugins = { // https://github.com/dividab/tsconfig-paths-webpack-plugin TsconfigPathsPlugin: require('tsconfig-paths-webpack-plugin'), // https://github.com/aackerman/circular-dependency-plugin - CircularDependencyPlugin: require('circular-dependency-plugin') + CircularDependencyPlugin: require('circular-dependency-plugin'), + // https://github.com/jantimon/html-webpack-plugin + HtmlWebpackPlugin: require('html-webpack-plugin'), + // https://github.com/mishoo/UglifyJS2/tree/harmony + UglifyJsPlugin: require('uglifyjs-webpack-plugin'), + // https://www.npmjs.com/package/@ngtools/webpack + NgToolsWebpack: require('@ngtools/webpack'), + // https://github.com/NMFR/optimize-css-assets-webpack-plugin + OptimizeCSSAssetsPlugin: require("optimize-css-assets-webpack-plugin"), + // https://github.com/jrparish/tslint-webpack-plugin + TsLintPlugin: require('tslint-webpack-plugin') }; -const isDevServer = path.basename(require.main.filename) === 'webpack-dev-server.js'; +module.exports = function(env) { + const isDevServer = path.basename(require.main.filename) === 'webpack-dev-server.js'; + const isProduction = env && env.production; + const isTesting = env && env.target === 'tests'; + const isCoverage = env && env.coverage; + const isJit = env && env.jit; + + const config = { + mode: isProduction ? 'production' : 'development', -module.exports = { - /** - * Options affecting the resolving of modules. - * - * See: https://webpack.js.org/configuration/resolve/ - */ - resolve: { /** - * An array of extensions that should be used to resolve modules. + * Source map for Karma from the help of karma-sourcemap-loader & karma-webpack. * - * See: https://webpack.js.org/configuration/resolve/#resolve-extensions + * See: https://webpack.js.org/configuration/devtool/ */ - extensions: ['.js', '.mjs', '.ts', '.css', '.scss'], - modules: [ - helpers.root('app'), - helpers.root('app', 'theme'), - helpers.root('node_modules') - ], + devtool: isProduction ? undefined : (isTesting ? 'inline-source-map' : 'source-map'), + + /** + * Options affecting the resolving of modules. + * + * See: https://webpack.js.org/configuration/resolve/ + */ + resolve: { + /** + * An array of extensions that should be used to resolve modules. + * + * See: https://webpack.js.org/configuration/resolve/#resolve-extensions + */ + extensions: ['.js', '.mjs', '.ts', '.css', '.scss'], + modules: [ + root('app'), + root('app', 'theme'), + root('node_modules') + ], + + plugins: [ + new plugins.TsconfigPathsPlugin() + ] + }, + + /** + * Options affecting the normal modules. + * + * See: https://webpack.js.org/configuration/module/ + */ + module: { + /** + * An array of Rules which are matched to requests when modules are created. + * + * See: https://webpack.js.org/configuration/module/#module-rules + */ + rules: [{ + test: /\.mjs$/, + type: "javascript/auto", + include: [/node_modules/] + }, { + test: /[\/\\]@angular[\/\\]core[\/\\].+\.js$/, + parser: { system: true }, + include: [/node_modules/] + }, { + test: /\.js\.flow$/, + use: [{ + loader: 'ignore-loader' + }], + include: [/node_modules/] + }, { + test: /\.html$/, + use: [{ + loader: 'raw-loader' + }] + }, { + test: /\.(woff|woff2|ttf|eot)(\?.*$|$)/, + use: [{ + loader: 'file-loader?name=[name].[hash].[ext]', + options: { + outputPath: 'assets', + /* + * Use custom public path as ./ is not supported by fonts. + */ + publicPath: isDevServer ? undefined : 'assets' + } + }] + }, { + test: /\.(png|jpe?g|gif|svg|ico)(\?.*$|$)/, + use: [{ + loader: 'file-loader?name=[name].[hash].[ext]', + options: { + outputPath: 'assets' + } + }] + }, { + test: /\.css$/, + use: [ + plugins.MiniCssExtractPlugin.loader, + { + loader: 'css-loader' + }] + }, { + test: /\.scss$/, + use: [{ + loader: 'raw-loader' + }, { + loader: 'sass-loader', options: { includePaths: [root('app', 'theme')] } + }], + exclude: root('app', 'theme') + }] + }, plugins: [ - new plugins.TsconfigPathsPlugin() - ] - }, - - /** - * Options affecting the normal modules. - * - * See: https://webpack.js.org/configuration/module/ - */ - module: { + new webpack.ContextReplacementPlugin(/\@angular(\\|\/)core(\\|\/)fesm5/, root('./app'), {}), + new webpack.ContextReplacementPlugin(/moment[\/\\]locale$/, /en/), + + /** + * Puts each bundle into a file and appends the hash of the file to the path. + * + * See: https://github.com/webpack-contrib/mini-css-extract-plugin + */ + new plugins.MiniCssExtractPlugin('[name].css'), + + new webpack.LoaderOptionsPlugin({ + options: { + htmlLoader: { + /** + * Define the root for images, so that we can use absolute urls. + * + * See: https://github.com/webpack/html-loader#Advanced_Options + */ + root: root('app', 'images') + }, + context: '/' + } + }), + + /** + * Detect circular dependencies in app. + * + * See: https://github.com/aackerman/circular-dependency-plugin + */ + new plugins.CircularDependencyPlugin({ + exclude: /([\\\/]node_modules[\\\/])|(ngfactory\.js$)/, + // Add errors to webpack instead of warnings + failOnError: true + }), + ], + + devServer: { + headers: { + 'Access-Control-Allow-Origin': '*' + }, + historyApiFallback: true + } + }; + + if (!isTesting) { /** - * An array of Rules which are matched to requests when modules are created. + * The entry point for the bundle. Our Angular app. * - * See: https://webpack.js.org/configuration/module/#module-rules + * See: https://webpack.js.org/configuration/entry-context/ */ - rules: [{ - test: /\.mjs$/, - type: "javascript/auto", - include: [/node_modules/] - }, { - test: /[\/\\]@angular[\/\\]core[\/\\].+\.js$/, - parser: { system: true }, - include: [/node_modules/] - }, { + config.entry = { + 'shims': './app/shims.ts', + 'app': './app/app.ts' + }; + + if (isProduction) { + config.output = { + /** + * The output directory as absolute path (required). + * + * See: https://webpack.js.org/configuration/output/#output-path + */ + path: root('wwwroot/build/'), + + publicPath: './build/', + + /** + * Specifies the name of each output file on disk. + * + * See: https://webpack.js.org/configuration/output/#output-filename + */ + filename: '[name].js', + + /** + * The filename of non-entry chunks as relative path inside the output.path directory. + * + * See: https://webpack.js.org/configuration/output/#output-chunkfilename + */ + chunkFilename: '[id].[hash].chunk.js' + }; + } else { + config.output = { + filename: '[name].js', + + /** + * Set the public path, because we are running the website from another port (5000). + */ + publicPath: 'http://localhost:3000/' + }; + } + + config.plugins.push( + new plugins.HtmlWebpackPlugin({ + hash: true, + chunks: ['shims', 'app'], + chunksSortMode: 'manual', + template: 'wwwroot/index.html' + }) + ); + + config.plugins.push( + new plugins.HtmlWebpackPlugin({ + template: 'wwwroot/_theme.html', hash: true, chunksSortMode: 'none', filename: 'theme.html' + }) + ); + + config.plugins.push( + new plugins.TsLintPlugin({ + files: ['./app/**/*.ts'], + /** + * Path to a configuration file. + */ + config: root('tslint.json'), + /** + * Wait for linting and fail the build when linting error occur. + */ + waitForLinting: isProduction + }) + ); + } + + if (isProduction) { + config.optimization = { + minimizer: [ + new plugins.UglifyJsPlugin({ + uglifyOptions: { + compress: false, + ecma: 6, + mangle: true, + output: { + comments: false + } + }, + extractComments: true + }), + + new plugins.OptimizeCSSAssetsPlugin({}) + ] + }; + + config.performance = { + hints: false + }; + } + + if (!isCoverage) { + config.module.rules.push({ test: /\.ts$/, use: [{ loader: 'awesome-typescript-loader' - }, { - loader: 'angular-router-loader' - }, { - loader: 'angular2-template-loader' }], exclude: [/node_modules/] - }, { + }) + } else { + config.module.rules.push({ test: /\.ts$/, use: [{ - loader: 'awesome-typescript-loader' + loader: 'ts-loader' }], - include: [/node_modules/] - }, { - test: /\.js\.flow$/, + include: [/\.(e2e|spec)\.ts$/], + }); + + // Use instrument loader for all normal builds. + config.module.rules.push({ + test: /\.ts$/, use: [{ - loader: 'ignore-loader' + loader: 'istanbul-instrumenter-loader' + }, { + loader: 'ts-loader' }], - include: [/node_modules/] - }, { - test: /\.html$/, - use: [{ - loader: 'raw-loader' - }] - }, { - test: /\.(woff|woff2|ttf|eot)(\?.*$|$)/, - use: [{ - loader: 'file-loader?name=[name].[hash].[ext]', - options: { - outputPath: 'assets', - /* - * Use custom public path as ./ is not supported by fonts. - */ - publicPath: isDevServer ? undefined : 'assets' - } - }] - }, { - test: /\.(png|jpe?g|gif|svg|ico)(\?.*$|$)/, - use: [{ - loader: 'file-loader?name=[name].[hash].[ext]', - options: { - outputPath: 'assets' - } - }] - }, { - test: /\.css$/, + exclude: [/\.(e2e|spec)\.ts$/] + }); + } + + if (isProduction) { + config.module.rules.push({ + test: /\.scss$/, + /* + * Extract the content from a bundle to a file. + * + * See: https://github.com/webpack-contrib/extract-text-webpack-plugin + */ use: [ plugins.MiniCssExtractPlugin.loader, { loader: 'css-loader' - }] - }, { + }, { + loader: 'sass-loader' + }], + /* + * Do not include component styles. + */ + include: root('app', 'theme'), + }); + } else { + config.module.rules.push({ test: /\.scss$/, use: [{ - loader: 'raw-loader' + loader: 'style-loader' }, { - loader: 'sass-loader', options: { includePaths: [helpers.root('app', 'theme')] } + loader: 'css-loader' + }, { + loader: 'sass-loader?sourceMap' }], - exclude: helpers.root('app', 'theme') - }] - }, + /* + * Do not include component styles. + */ + include: root('app', 'theme') + }); + } - plugins: [ - /** - * Puts each bundle into a file and appends the hash of the file to the path. - * - * See: https://github.com/webpack-contrib/mini-css-extract-plugin - */ - new plugins.MiniCssExtractPlugin('[name].css'), - - new webpack.LoaderOptionsPlugin({ - options: { - 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') - }, - context: '/' - } - }), - - new plugins.CircularDependencyPlugin({ - exclude: /([\\\/]node_modules[\\\/])|(ngfactory\.js$)/, - // Add errors to webpack instead of warnings - failOnError: true - }), - - new webpack.ContextReplacementPlugin(/moment[\/\\]locale$/, /en/) - ] + if (!isJit) { + config.module.rules.push({ + test: /(?:\.ngfactory\.js|\.ngstyle\.js|\.ts)$/, + use: [{ + loader: '@ngtools/webpack' + }] + }); + + config.plugins.push( + new plugins.NgToolsWebpack.AngularCompilerPlugin({ + entryModule: 'app/app.module#AppModule', + sourceMap: !isProduction, + skipSourceGeneration: false, + tsConfigPath: './tsconfig.json' + }) + ); + } + + return config; }; \ No newline at end of file diff --git a/src/Squidex/app-config/webpack.run.base.js b/src/Squidex/app-config/webpack.run.base.js deleted file mode 100644 index 06012fa60..000000000 --- a/src/Squidex/app-config/webpack.run.base.js +++ /dev/null @@ -1,35 +0,0 @@ -const webpack = require('webpack'), - webpackMerge = require('webpack-merge'), - path = require('path'), - helpers = require('./helpers'), - commonConfig = require('./webpack.config.js'); - -const plugins = { - // https://github.com/jantimon/html-webpack-plugin - HtmlWebpackPlugin: require('html-webpack-plugin') -}; - -module.exports = webpackMerge(commonConfig, { - /** - * The entry point for the bundle. Our Angular app. - * - * See: https://webpack.js.org/configuration/entry-context/ - */ - entry: { - 'shims': './app/shims.ts', - 'app': './app/app.ts' - }, - - plugins: [ - new plugins.HtmlWebpackPlugin({ - hash: true, - chunks: ['shims', 'app'], - chunksSortMode: 'manual', - template: 'wwwroot/index.html' - }), - - new plugins.HtmlWebpackPlugin({ - template: 'wwwroot/_theme.html', hash: true, chunksSortMode: 'none', filename: 'theme.html' - }) - ] -}); \ No newline at end of file diff --git a/src/Squidex/app-config/webpack.run.dev.js b/src/Squidex/app-config/webpack.run.dev.js deleted file mode 100644 index 5a34d49d9..000000000 --- a/src/Squidex/app-config/webpack.run.dev.js +++ /dev/null @@ -1,68 +0,0 @@ -const webpack = require('webpack'), - webpackMerge = require('webpack-merge'), - path = require('path'), - helpers = require('./helpers'), - runConfig = require('./webpack.run.base.js'); - -const plugins = { - // https://github.com/jrparish/tslint-webpack-plugin - TsLintPlugin: require('tslint-webpack-plugin') -}; - -module.exports = webpackMerge(runConfig, { - mode: 'development', - - devtool: 'source-map', - - output: { - filename: '[name].js', - - /** - * Set the public path, because we are running the website from another port (5000). - */ - publicPath: 'http://localhost:3000/' - }, - - /* - * Options affecting the normal modules. - * - * See: https://webpack.js.org/configuration/module/ - */ - module: { - /** - * An array of Rules which are matched to requests when modules are created. - * - * See: https://webpack.js.org/configuration/module/#module-rules - */ - rules: [{ - test: /\.scss$/, - use: [{ - loader: 'style-loader' - }, { - loader: 'css-loader' - }, { - loader: 'sass-loader?sourceMap', options: { includePaths: [helpers.root('app', 'theme')] } - }], - include: helpers.root('app', 'theme') - }] - }, - - plugins: [ - new webpack.ContextReplacementPlugin(/\@angular(\\|\/)core(\\|\/)fesm5/, helpers.root('./src'), {}), - - new plugins.TsLintPlugin({ - files: ['./app/**/*.ts'], - /** - * Path to a configuration file. - */ - config: helpers.root('tslint.json') - }) - ], - - devServer: { - headers: { - 'Access-Control-Allow-Origin': '*' - }, - historyApiFallback: true - } -}); \ No newline at end of file diff --git a/src/Squidex/app-config/webpack.run.prod.js b/src/Squidex/app-config/webpack.run.prod.js deleted file mode 100644 index 07fbca634..000000000 --- a/src/Squidex/app-config/webpack.run.prod.js +++ /dev/null @@ -1,137 +0,0 @@ -const webpack = require('webpack'), - webpackMerge = require('webpack-merge'), - path = require('path'), - helpers = require('./helpers'), - runConfig = require('./webpack.run.base.js'); - -const plugins = { - // https://github.com/mishoo/UglifyJS2/tree/harmony - UglifyJsPlugin: require('uglifyjs-webpack-plugin'), - // https://www.npmjs.com/package/@ngtools/webpack - NgToolsWebpack: require('@ngtools/webpack'), - // https://github.com/webpack-contrib/mini-css-extract-plugin - MiniCssExtractPlugin: require('mini-css-extract-plugin'), - // https://github.com/NMFR/optimize-css-assets-webpack-plugin - OptimizeCSSAssetsPlugin: require("optimize-css-assets-webpack-plugin"), - // https://github.com/jrparish/tslint-webpack-plugin - TsLintPlugin: require('tslint-webpack-plugin') -}; - -helpers.removeLoaders(runConfig, ['scss', 'ts']); - -module.exports = webpackMerge(runConfig, { - mode: 'production', - - output: { - /** - * The output directory as absolute path (required). - * - * See: https://webpack.js.org/configuration/output/#output-path - */ - path: helpers.root('wwwroot/build/'), - - publicPath: './build/', - - /** - * Specifies the name of each output file on disk. - * - * See: https://webpack.js.org/configuration/output/#output-filename - */ - filename: '[name].js', - - /** - * The filename of non-entry chunks as relative path inside the output.path directory. - * - * See: https://webpack.js.org/configuration/output/#output-chunkfilename - */ - chunkFilename: '[id].[hash].chunk.js' - }, - - /* - * Options affecting the normal modules. - * - * See: https://webpack.js.org/configuration/module/ - */ - module: { - /** - * An array of Rules which are matched to requests when modules are created. - * - * See: https://webpack.js.org/configuration/module/#module-rules - */ - rules: [{ - test: /\.scss$/, - /* - * Extract the content from a bundle to a file. - * - * See: https://github.com/webpack-contrib/extract-text-webpack-plugin - */ - use: [ - plugins.MiniCssExtractPlugin.loader, - { - loader: 'css-loader' - }, { - loader: 'sass-loader' - }], - /* - * Do not include component styles. - */ - include: helpers.root('app', 'theme'), - }, { - test: /\.scss$/, - use: [{ - loader: 'raw-loader' - }, { - loader: 'sass-loader', options: { includePaths: [helpers.root('app', 'theme')] } - }], - exclude: helpers.root('app', 'theme'), - }, { - test: /(?:\.ngfactory\.js|\.ngstyle\.js|\.ts)$/, - use: [{ - loader: '@ngtools/webpack' - }] - }] - }, - - plugins: [ - new plugins.NgToolsWebpack.AngularCompilerPlugin({ - entryModule: 'app/app.module#AppModule', - sourceMap: false, - skipSourceGeneration: false, - tsConfigPath: './tsconfig.json' - }), - - new plugins.TsLintPlugin({ - files: ['./app/**/*.ts'], - /** - * Path to a configuration file. - */ - config: helpers.root('tslint.json'), - /** - * Wait for linting and fail the build when linting error occur. - */ - waitForLinting: true - }) - ], - - optimization: { - minimizer: [ - new plugins.UglifyJsPlugin({ - uglifyOptions: { - compress: false, - ecma: 6, - mangle: true, - output: { - comments: false - } - }, - extractComments: true - }), - - new plugins.OptimizeCSSAssetsPlugin({}) - ] - }, - - performance: { - hints: false - } -}); \ 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 deleted file mode 100644 index 1989b80d4..000000000 --- a/src/Squidex/app-config/webpack.test.coverage.js +++ /dev/null @@ -1,37 +0,0 @@ -const webpack = require('webpack'), - webpackMerge = require('webpack-merge'), - path = require('path'), - helpers = require('./helpers'), - testConfig = require('./webpack.test.js'); - -helpers.removeLoaders(testConfig, ['ts']); - -module.exports = webpackMerge(testConfig, { - module: { - /** - * An array of Rules which are matched to requests when modules are created. - * - * See: https://webpack.js.org/configuration/module/#module-rules - */ - rules: [{ - test: /\.ts$/, - use: [{ - loader: 'ts-loader' - }], - include: [/\.(e2e|spec)\.ts$/], - - }, { - test: /\.ts$/, - use: [{ - loader: 'istanbul-instrumenter-loader' - }, { - loader: 'ts-loader' - }, { - loader: 'angular-router-loader' - }, { - loader: 'angular2-template-loader' - }], - exclude: [/\.(e2e|spec)\.ts$/] - }] - } -}); \ No newline at end of file diff --git a/src/Squidex/app-config/webpack.test.js b/src/Squidex/app-config/webpack.test.js deleted file mode 100644 index eacdb4361..000000000 --- a/src/Squidex/app-config/webpack.test.js +++ /dev/null @@ -1,16 +0,0 @@ -const webpack = require('webpack'), - webpackMerge = require('webpack-merge'), - path = require('path'), - helpers = require('./helpers'), - commonConfig = require('./webpack.config.js'); - -module.exports = webpackMerge(commonConfig, { - mode: 'development', - - /** - * Source map for Karma from the help of karma-sourcemap-loader & karma-webpack. - * - * See: https://webpack.js.org/configuration/devtool/ - */ - devtool: 'inline-source-map' -}); \ No newline at end of file diff --git a/src/Squidex/app/shared/state/assets.state.spec.ts b/src/Squidex/app/shared/state/assets.state.spec.ts index 17f604219..cf9e52d59 100644 --- a/src/Squidex/app/shared/state/assets.state.spec.ts +++ b/src/Squidex/app/shared/state/assets.state.spec.ts @@ -54,13 +54,15 @@ describe('AssetsState', () => { }); describe('Loading', () => { + beforeEach(() => { + assetsService.setup(x => x.getTags(app)) + .returns(() => of({ tag1: 1, shared: 2, tag2: 1 })).verifiable(Times.atLeastOnce()); + }); + it('should load assets', () => { assetsService.setup(x => x.getAssets(app, 30, 0, undefined, [])) .returns(() => of(new AssetsDto(200, oldAssets))).verifiable(); - assetsService.setup(x => x.getTags(app)) - .returns(() => of({ tag1: 1, shared: 2, tag2: 1 })).verifiable(); - assetsState.load().subscribe(); expect(assetsState.snapshot.assets.values).toEqual(oldAssets); @@ -72,10 +74,7 @@ describe('AssetsState', () => { it('should show notification on load when reload is true', () => { assetsService.setup(x => x.getAssets(app, 30, 0, undefined, [])) - .returns(() => of(new AssetsDto(200, oldAssets))); - - assetsService.setup(x => x.getTags(app)) - .returns(() => of({ tag1: 1, shared: 2, tag2: 1 })).verifiable(); + .returns(() => of(new AssetsDto(200, oldAssets))).verifiable(); assetsState.load(true).subscribe(); @@ -86,7 +85,7 @@ describe('AssetsState', () => { it('should load with tags when tag toggled', () => { assetsService.setup(x => x.getAssets(app, 30, 0, undefined, ['tag1'])) - .returns(() => of(new AssetsDto(0, []))); + .returns(() => of(new AssetsDto(0, []))).verifiable(); assetsState.toggleTag('tag1').subscribe(); @@ -95,10 +94,10 @@ describe('AssetsState', () => { it('should load without tags when tag toggled', () => { assetsService.setup(x => x.getAssets(app, 30, 0, undefined, ['tag1'])) - .returns(() => of(new AssetsDto(0, []))); + .returns(() => of(new AssetsDto(0, []))).verifiable(); assetsService.setup(x => x.getAssets(app, 30, 0, undefined, [])) - .returns(() => of(new AssetsDto(0, []))); + .returns(() => of(new AssetsDto(0, []))).verifiable(); assetsState.toggleTag('tag1').subscribe(); assetsState.toggleTag('tag1').subscribe(); @@ -108,7 +107,7 @@ describe('AssetsState', () => { it('should load with tags when tags selected', () => { assetsService.setup(x => x.getAssets(app, 30, 0, undefined, ['tag1', 'tag2'])) - .returns(() => of(new AssetsDto(0, []))); + .returns(() => of(new AssetsDto(0, []))).verifiable(); assetsState.selectTags(['tag1', 'tag2']).subscribe(); @@ -117,7 +116,7 @@ describe('AssetsState', () => { it('should load without tags when tags reset', () => { assetsService.setup(x => x.getAssets(app, 30, 0, undefined, [])) - .returns(() => of(new AssetsDto(0, []))); + .returns(() => of(new AssetsDto(0, []))).verifiable(); assetsState.resetTags().subscribe(); @@ -125,9 +124,13 @@ describe('AssetsState', () => { }); it('should load next page and prev page when paging', () => { + assetsService.setup(x => x.getAssets(app, 30, 0, undefined, [])) + .returns(() => of(new AssetsDto(200, []))).verifiable(Times.exactly(2)); + assetsService.setup(x => x.getAssets(app, 30, 30, undefined, [])) - .returns(() => of(new AssetsDto(200, []))); + .returns(() => of(new AssetsDto(200, []))).verifiable(); + assetsState.load().subscribe(); assetsState.goNext().subscribe(); assetsState.goPrev().subscribe(); @@ -136,7 +139,7 @@ describe('AssetsState', () => { it('should load with query when searching', () => { assetsService.setup(x => x.getAssets(app, 30, 0, 'my-query', [])) - .returns(() => of(new AssetsDto(0, []))); + .returns(() => of(new AssetsDto(0, []))).verifiable(); assetsState.search('my-query').subscribe(); diff --git a/src/Squidex/app/shims.ts b/src/Squidex/app/shims.ts index 4c18a84a4..f2b179e2a 100644 --- a/src/Squidex/app/shims.ts +++ b/src/Squidex/app/shims.ts @@ -92,6 +92,4 @@ import 'core-js/modules/es.set'; import 'core-js/modules/es.weak-map'; import 'core-js/modules/web.dom-collections.iterator'; -import 'core-js/proposals/reflect-metadata'; - import 'zone.js/dist/zone'; \ No newline at end of file diff --git a/src/Squidex/package-lock.json b/src/Squidex/package-lock.json index 183d8b57a..721adebda 100644 --- a/src/Squidex/package-lock.json +++ b/src/Squidex/package-lock.json @@ -1669,15 +1669,6 @@ "integrity": "sha1-SlKCrBZHKek2Gbz9OtFR+BfOkfU=", "dev": true }, - "angular-router-loader": { - "version": "0.8.5", - "resolved": "https://registry.npmjs.org/angular-router-loader/-/angular-router-loader-0.8.5.tgz", - "integrity": "sha512-8wggCTKGgzB1o8co3Wvj+p9pKN7T7q3C477lEz3NLjvPVzUti8rv9i45Di+4aO/k+HvzGh3s8QdNlXU2Bl4avQ==", - "dev": true, - "requires": { - "loader-utils": "^1.0.2" - } - }, "angular2-chartjs": { "version": "0.5.1", "resolved": "https://registry.npmjs.org/angular2-chartjs/-/angular2-chartjs-0.5.1.tgz", @@ -1686,29 +1677,6 @@ "chart.js": "^2.3.0" } }, - "angular2-template-loader": { - "version": "0.6.2", - "resolved": "https://registry.npmjs.org/angular2-template-loader/-/angular2-template-loader-0.6.2.tgz", - "integrity": "sha1-wNROkP/w+sleiyPwQ6zaf9HFHXw=", - "dev": true, - "requires": { - "loader-utils": "^0.2.15" - }, - "dependencies": { - "loader-utils": { - "version": "0.2.17", - "resolved": "https://registry.npmjs.org/loader-utils/-/loader-utils-0.2.17.tgz", - "integrity": "sha1-+G5jdNQyBabmxg6RlvF8Apm/s0g=", - "dev": true, - "requires": { - "big.js": "^3.1.3", - "emojis-list": "^2.0.0", - "json5": "^0.5.0", - "object-assign": "^4.0.1" - } - } - } - }, "ansi-colors": { "version": "3.2.4", "resolved": "https://registry.npmjs.org/ansi-colors/-/ansi-colors-3.2.4.tgz", @@ -2879,14 +2847,13 @@ } }, "browserslist": { - "version": "4.3.5", - "resolved": "https://registry.npmjs.org/browserslist/-/browserslist-4.3.5.tgz", - "integrity": "sha512-z9ZhGc3d9e/sJ9dIx5NFXkKoaiQTnrvrMsN3R1fGb1tkWWNSz12UewJn9TNxGo1l7J23h0MRaPmk7jfeTZYs1w==", - "dev": true, + "version": "4.6.1", + "resolved": "https://registry.npmjs.org/browserslist/-/browserslist-4.6.1.tgz", + "integrity": "sha512-1MC18ooMPRG2UuVFJTHFIAkk6mpByJfxCrnUyvSlu/hyQSFHMrlhM02SzNuCV+quTP4CKmqtOMAIjrifrpBJXQ==", "requires": { - "caniuse-lite": "^1.0.30000912", - "electron-to-chromium": "^1.3.86", - "node-releases": "^1.0.5" + "caniuse-lite": "^1.0.30000971", + "electron-to-chromium": "^1.3.137", + "node-releases": "^1.1.21" } }, "buffer": { @@ -3133,10 +3100,9 @@ } }, "caniuse-lite": { - "version": "1.0.30000918", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30000918.tgz", - "integrity": "sha512-CAZ9QXGViBvhHnmIHhsTPSWFBujDaelKnUj7wwImbyQRxmXynYqKGi3UaZTSz9MoVh+1EVxOS/DFIkrJYgR3aw==", - "dev": true + "version": "1.0.30000971", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30000971.tgz", + "integrity": "sha512-TQFYFhRS0O5rdsmSbF1Wn+16latXYsQJat66f7S7lizXW1PVpWJeZw9wqqVLIjuxDRz7s7xRUj13QCfd8hKn6g==" }, "canonical-path": { "version": "1.0.0", @@ -4600,10 +4566,9 @@ "dev": true }, "electron-to-chromium": { - "version": "1.3.90", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.90.tgz", - "integrity": "sha512-IjJZKRhFbWSOX1w0sdIXgp4CMRguu6UYcTckyFF/Gjtemsu/25eZ+RXwFlV+UWcIueHyQA1UnRJxocTpH5NdGA==", - "dev": true + "version": "1.3.142", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.142.tgz", + "integrity": "sha512-GLOB/wAA2g9l5Hwg1XrPqd6br2WNOPIY8xl/q+g5zZdv3b5fB69oFOooxKxc0DfDfDS1RqaF6hKjwt6v4fuFUw==" }, "elliptic": { "version": "6.4.1", @@ -10352,10 +10317,9 @@ } }, "node-releases": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/node-releases/-/node-releases-1.1.1.tgz", - "integrity": "sha512-2UXrBr6gvaebo5TNF84C66qyJJ6r0kxBObgZIDX3D3/mt1ADKiHux3NJPWisq0wxvJJdkjECH+9IIKYViKj71Q==", - "dev": true, + "version": "1.1.22", + "resolved": "https://registry.npmjs.org/node-releases/-/node-releases-1.1.22.tgz", + "integrity": "sha512-O6XpteBuntW1j86mw6LlovBIwTe+sO2+7vi9avQffNeIW4upgnaCVm6xrBWH+KATz7mNNRNNeEpuWB7dT6Cr3w==", "requires": { "semver": "^5.3.0" } @@ -13206,8 +13170,7 @@ "semver": { "version": "5.5.0", "resolved": "https://registry.npmjs.org/semver/-/semver-5.5.0.tgz", - "integrity": "sha512-4SJ3dm0WAwWy/NVeioZh5AntkdJoWKxHxcmyP622fOkgHa4z3R0TdBJICINyaSDE6uNwVc8gZr+ZinwZAH4xIA==", - "dev": true + "integrity": "sha512-4SJ3dm0WAwWy/NVeioZh5AntkdJoWKxHxcmyP622fOkgHa4z3R0TdBJICINyaSDE6uNwVc8gZr+ZinwZAH4xIA==" }, "semver-dsl": { "version": "1.0.1", @@ -17684,15 +17647,6 @@ "uuid": "^3.1.0" } }, - "webpack-merge": { - "version": "4.2.1", - "resolved": "https://registry.npmjs.org/webpack-merge/-/webpack-merge-4.2.1.tgz", - "integrity": "sha512-4p8WQyS98bUJcCvFMbdGZyZmsKuWjWVnVHnAS3FFg0HDaRVrPbkivx2RYCre8UiemD67RsiFFLfn4JhLAin8Vw==", - "dev": true, - "requires": { - "lodash": "^4.17.5" - } - }, "webpack-sources": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/webpack-sources/-/webpack-sources-1.2.0.tgz", diff --git a/src/Squidex/package.json b/src/Squidex/package.json index cf9b1f8af..7453f5829 100644 --- a/src/Squidex/package.json +++ b/src/Squidex/package.json @@ -6,12 +6,12 @@ "repository": "https://github.com/SebastianStehle/Squidex", "scripts": { "copy": "cpx node_modules/oidc-client/dist/oidc-client.min.js wwwroot/scripts/", - "start": "npm run copy && webpack-dev-server --config app-config/webpack.run.dev.js --inline --port 3000 --hot", + "start": "npm run copy && webpack-dev-server --config app-config/webpack.config.js --inline --port 3000 --hot", "test": "karma start", "test:coverage": "karma start karma.coverage.conf.js", "test:clean": "rimraf _test-output", "tslint": "tslint -c tslint.json -p tsconfig.json app/**/*.ts", - "build": "npm run copy && webpack --config app-config/webpack.run.prod.js", + "build": "npm run copy && webpack --config app-config/webpack.config.js --env.production", "build:clean": "rimraf wwwroot/build" }, "dependencies": { @@ -20,13 +20,15 @@ "@angular/core": "8.0.0", "@angular/forms": "8.0.0", "@angular/http": "7.2.15", - "@angular/platform-browser-dynamic": "8.0.0", "@angular/platform-browser": "8.0.0", + "@angular/platform-browser-dynamic": "8.0.0", "@angular/platform-server": "8.0.0", "@angular/router": "8.0.0", "angular2-chartjs": "0.5.1", "babel-polyfill": "6.26.0", "bootstrap": "4.3.1", + "browserslist": "^4.6.1", + "caniuse-lite": "^1.0.30000971", "core-js": "3.1.3", "graphiql": "0.13.0", "graphql": "14.3.1", @@ -38,8 +40,8 @@ "oidc-client": "1.7.1", "pikaday": "1.8.0", "progressbar.js": "1.0.1", - "react-dom": "16.8.6", "react": "16.8.6", + "react-dom": "16.8.6", "rxjs": "6.5.2", "slugify": "1.3.4", "sortablejs": "1.9.0", @@ -58,8 +60,6 @@ "@types/react-dom": "16.8.4", "@types/react": "16.8.19", "@types/sortablejs": "1.7.2", - "angular-router-loader": "0.8.5", - "angular2-template-loader": "0.6.2", "awesome-typescript-loader": "5.2.1", "babel-core": "6.26.3", "circular-dependency-plugin": "5.0.2", @@ -101,7 +101,6 @@ "underscore": "1.9.1", "webpack-cli": "3.3.2", "webpack-dev-server": "3.5.1", - "webpack-merge": "4.2.1", "webpack": "4.32.2" } }