From ed128d1f171c8a49fde4eea0ab6eadfde26faaab Mon Sep 17 00:00:00 2001 From: lotte Date: Wed, 5 Jun 2019 14:25:58 +0200 Subject: [PATCH] removed node env variable --- config/environment.default.js | 4 +- package.json | 4 +- webpack.config.js | 69 ++++---- webpack/helpers.js | 15 +- webpack/webpack.aot.js | 52 +++--- webpack/webpack.client.js | 36 ++-- webpack/webpack.common.js | 318 +++++++++++++++++----------------- webpack/webpack.server.js | 40 +++-- 8 files changed, 273 insertions(+), 265 deletions(-) diff --git a/config/environment.default.js b/config/environment.default.js index c3c6e0f386..5aac63fd3d 100644 --- a/config/environment.default.js +++ b/config/environment.default.js @@ -157,7 +157,7 @@ module.exports = { } }, theme: { - name: 'default', - cssClass: 'default', + name: 'mantis', + cssClass: 'mantis', } }; diff --git a/package.json b/package.json index 91fa430108..35da7c6f5d 100644 --- a/package.json +++ b/package.json @@ -25,8 +25,8 @@ "prebuild:aot": "yarn run prebuild", "prebuild:prod": "yarn run prebuild", "build": "node ./scripts/webpack.js --progress --mode development", - "build:aot": "yarn run syncbuilddir && node ./scripts/resolve-absolute-scss-imports.js && DSPACE_BUILD_DIR=./build node ./scripts/webpack.js --env.aot --env.server --mode development && DSPACE_BUILD_DIR=./build node ./scripts/webpack.js --env.aot --env.client --mode development", - "build:prod": "yarn run syncbuilddir && node ./scripts/resolve-absolute-scss-imports.js && DSPACE_BUILD_DIR=./build node ./scripts/webpack.js --env.aot --env.server --mode production && DSPACE_BUILD_DIR=./build node ./scripts/webpack.js --env.aot --env.client --mode production", + "build:aot": "yarn run syncbuilddir && node ./scripts/resolve-absolute-scss-imports.js && node ./scripts/webpack.js --env.aot --env.server --mode development && node ./scripts/webpack.js --env.aot --env.client --mode development", + "build:prod": "yarn run syncbuilddir && node ./scripts/resolve-absolute-scss-imports.js && node ./scripts/webpack.js --env.aot --env.server --mode production && node ./scripts/webpack.js --env.aot --env.client --mode production", "postbuild:prod": "yarn run rollup", "rollup": "rollup -c rollup.config.js", "prestart": "yarn run build:prod", diff --git a/webpack.config.js b/webpack.config.js index 6312cf3605..78ca2d98dc 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -1,46 +1,45 @@ const webpackMerge = require('webpack-merge'); -const commonPartial = require('./webpack/webpack.common'); -const clientPartial = require('./webpack/webpack.client'); -const { getServerWebpackPartial } = require('./webpack/webpack.server'); + const prodPartial = require('./webpack/webpack.prod'); -const { - getAotPlugin -} = require('./webpack/webpack.aot'); - -module.exports = function(env, options) { +module.exports = function (env, options) { env = env || {}; - if (env.aot) { - console.log(`Running build for ${env.client ? 'client' : 'server'} with AoT Compilation`) - } + const commonPartial = require('./webpack/webpack.common')(env); + const clientPartial = require('./webpack/webpack.client')(env); + const {getAotPlugin} = require('./webpack/webpack.aot')(env); + const {getServerWebpackPartial} = require('./webpack/webpack.server')(env); - let serverPartial = getServerWebpackPartial(env.aot); + if (env.aot) { + console.log(`Running build for ${env.client ? 'client' : 'server'} with AoT Compilation`) + } - let serverConfig = webpackMerge({}, commonPartial, serverPartial, { - plugins: [ - getAotPlugin('server', !!env.aot) - ] - }); + let serverPartial = getServerWebpackPartial(env.aot); - let clientConfig = webpackMerge({}, commonPartial, clientPartial, { - plugins: [ - getAotPlugin('client', !!env.aot) - ] - }); - if (options.mode === 'production') { - serverConfig = webpackMerge({}, serverConfig, prodPartial); - clientConfig = webpackMerge({}, clientConfig, prodPartial); - } + let serverConfig = webpackMerge({}, commonPartial, serverPartial, { + plugins: [ + getAotPlugin('server', !!env.aot) + ] + }); - const configs = []; + let clientConfig = webpackMerge({}, commonPartial, clientPartial, { + plugins: [ + getAotPlugin('client', !!env.aot) + ] + }); + if (options.mode === 'production') { + serverConfig = webpackMerge({}, serverConfig, prodPartial); + clientConfig = webpackMerge({}, clientConfig, prodPartial); + } - if (!env.aot) { - configs.push(clientConfig, serverConfig); - } else if (env.client) { - configs.push(clientConfig); - } else if (env.server) { - configs.push(serverConfig); - } + const configs = []; - return configs; + if (!env.aot) { + configs.push(clientConfig, serverConfig); + } else if (env.client) { + configs.push(clientConfig); + } else if (env.server) { + configs.push(serverConfig); + } + + return configs; }; diff --git a/webpack/helpers.js b/webpack/helpers.js index 435ca31b32..d8ea4d4b24 100644 --- a/webpack/helpers.js +++ b/webpack/helpers.js @@ -8,9 +8,10 @@ const projectRoot = (relativePath) => { const srcPath = projectRoot('src'); -const buildRoot = (relativePath) => { - if (process.env.DSPACE_BUILD_DIR) { - return path.resolve(projectRoot(process.env.DSPACE_BUILD_DIR), relativePath); +const buildRoot = (relativePath, env) => { + console.log(env.aot); + if (env.aot) { + return path.resolve(projectRoot('./build'), relativePath); } else { return path.resolve(projectRoot('src'), relativePath); } @@ -58,10 +59,10 @@ else { themePath = srcPath; } -const globalCSSImports = [ - buildRoot('styles/_variables.scss'), - buildRoot('styles/_mixins.scss'), -]; +const globalCSSImports = (env) => { return [ + buildRoot('styles/_variables.scss', env), + buildRoot('styles/_mixins.scss', env), +]}; const themeReplaceOptions = { diff --git a/webpack/webpack.aot.js b/webpack/webpack.aot.js index 6302c34519..c4b970892f 100644 --- a/webpack/webpack.aot.js +++ b/webpack/webpack.aot.js @@ -1,35 +1,37 @@ const { - buildRoot + buildRoot } = require('./helpers'); const { - AngularCompilerPlugin + AngularCompilerPlugin } = require('@ngtools/webpack'); -const tsconfigs = { - client: buildRoot('./tsconfig.browser.json'), - server: buildRoot('./tsconfig.server.json') -}; +module.exports = (env) => { + const tsconfigs = { + client: buildRoot('./tsconfig.browser.json', env), + server: buildRoot('./tsconfig.server.json', env) + }; -const aotTsconfigs = { - client: buildRoot('./tsconfig.browser.json'), - server: buildRoot('./tsconfig.server.aot.json') -}; + const aotTsconfigs = { + client: buildRoot('./tsconfig.browser.json', env), + server: buildRoot('./tsconfig.server.aot.json', env) + }; -/** - * Generates a AotPlugin for @ngtools/webpack - * - * @param {string} platform Should either be client or server - * @param {boolean} aot Enables/Disables AoT Compilation - * @returns {AotPlugin} Configuration of AotPlugin - */ -function getAotPlugin(platform, aot) { - return new AngularCompilerPlugin({ - tsConfigPath: aot ? aotTsconfigs[platform] : tsconfigs[platform], - skipCodeGeneration: !aot - }); -} + /** + * Generates a AotPlugin for @ngtools/webpack + * + * @param {string} platform Should either be client or server + * @param {boolean} aot Enables/Disables AoT Compilation + * @returns {AotPlugin} Configuration of AotPlugin + */ + function getAotPlugin(platform, aot) { + return new AngularCompilerPlugin({ + tsConfigPath: aot ? aotTsconfigs[platform] : tsconfigs[platform], + skipCodeGeneration: !aot + }); + } -module.exports = { - getAotPlugin: getAotPlugin + return { + getAotPlugin: getAotPlugin + } }; diff --git a/webpack/webpack.client.js b/webpack/webpack.client.js index 44d43aa739..ce49f60ed0 100644 --- a/webpack/webpack.client.js +++ b/webpack/webpack.client.js @@ -6,20 +6,22 @@ const { buildRoot } = require('./helpers'); -module.exports = { - entry: buildRoot('./main.browser.ts'), - output: { - filename: 'client.js' - }, - target: 'web', - plugins: [ - new HtmlWebpackPlugin({ - template: buildRoot('./index.html'), - output: projectRoot('dist'), - inject: 'head' - }), - new ScriptExtPlugin({ - defaultAttribute: 'defer' - }) - ] -}; +module.exports = (env) => { + return { + entry: buildRoot('./main.browser.ts', env), + output: { + filename: 'client.js' + }, + target: 'web', + plugins: [ + new HtmlWebpackPlugin({ + template: buildRoot('./index.html', env), + output: projectRoot('dist'), + inject: 'head' + }), + new ScriptExtPlugin({ + defaultAttribute: 'defer' + }) + ] + }; +} diff --git a/webpack/webpack.common.js b/webpack/webpack.common.js index e935cc3c8d..4eec4f46fb 100644 --- a/webpack/webpack.common.js +++ b/webpack/webpack.common.js @@ -1,167 +1,169 @@ const CopyWebpackPlugin = require('copy-webpack-plugin'); const path = require('path'); const { - projectRoot, - buildRoot, - globalCSSImports, - themeReplaceOptions, - themePath, - themedTest, - themedUse + projectRoot, + buildRoot, + globalCSSImports, + themeReplaceOptions, + themePath, + themedTest, + themedUse } = require('./helpers'); -module.exports = { - mode: 'development', - devtool: 'source-map', - resolve: { - extensions: ['.ts', '.js', '.json'] - }, - output: { - path: projectRoot('dist') - }, - watchOptions: { - aggregateTimeout: 50, - }, - node: { - fs: "empty", - module: "empty" - }, - module: { - rules: [ - { - test: (filePath) => themedTest(filePath, 'scss'), - use: (info) => themedUse(info.resource, 'scss') - }, - { - test: (filePath) => themedTest(filePath, 'html'), - use: (info) => themedUse(info.resource, 'html') - }, - { - test: /\.ts$/, - loader: '@ngtools/webpack' - }, - { - test: /\.css$/, - use: [ - { - loader: 'to-string-loader', - options: { - sourceMap: true +module.exports = (env) => { + return { + mode: 'development', + devtool: 'source-map', + resolve: { + extensions: ['.ts', '.js', '.json'] + }, + output: { + path: projectRoot('dist') + }, + watchOptions: { + aggregateTimeout: 50, + }, + node: { + fs: "empty", + module: "empty" + }, + module: { + rules: [ + { + test: (filePath) => themedTest(filePath, 'scss'), + use: (info) => themedUse(info.resource, 'scss') + }, + { + test: (filePath) => themedTest(filePath, 'html'), + use: (info) => themedUse(info.resource, 'html') + }, + { + test: /\.ts$/, + loader: '@ngtools/webpack' + }, + { + test: /\.css$/, + use: [ + { + loader: 'to-string-loader', + options: { + sourceMap: true + } + }, + { + loader: 'css-loader', + options: { + sourceMap: true, + modules: true + } + }, + { + loader: 'postcss-loader', + options: { + sourceMap: true + } + } + ] + }, + { + test: /\.scss$/, + exclude: [ + /node_modules/, + buildRoot('styles/_exposed_variables.scss', env), + buildRoot('styles/_variables.scss', env) + ], + use: [ + { + loader: 'raw-loader', + options: { + sourceMap: true + } + }, + { + loader: 'postcss-loader', + options: { + sourceMap: true + } + }, + { + loader: 'resolve-url-loader', + options: { + sourceMap: true + } + }, + { + loader: 'sass-loader', + options: { + sourceMap: true, + includePaths: [path.join(themePath, 'styles')] + } + }, + { + loader: 'sass-resources-loader', + options: { + resources: globalCSSImports(env) + }, + }, + { + loader: 'string-replace-loader', + options: themeReplaceOptions + } + ] + }, + { + test: /(_exposed)?_variables.scss$/, + exclude: [/node_modules/], + use: [ + { + loader: 'css-loader', + options: { + sourceMap: true, + modules: true + } + }, + { + loader: 'postcss-loader', + options: { + sourceMap: true + } + }, + { + loader: 'resolve-url-loader', + options: { + sourceMap: true + } + }, + { + loader: 'sass-loader', + options: { + sourceMap: true, + includePaths: [path.join(themePath, 'styles')] + } + }, + { + loader: 'string-replace-loader', + options: themeReplaceOptions + } + ] + }, + { + test: /\.html$/, + loader: 'raw-loader' + } + ] + }, + plugins: [ + new CopyWebpackPlugin([{ + from: path.join(__dirname, '..', 'node_modules', '@fortawesome', 'fontawesome-free', 'webfonts'), + to: path.join('assets', 'fonts') + }, { + from: path.join(__dirname, '..', 'resources', 'images'), + to: path.join('assets', 'images') + }, { + from: path.join(__dirname, '..', 'resources', 'i18n'), + to: path.join('assets', 'i18n') } - }, - { - loader: 'css-loader', - options: { - sourceMap: true, - modules: true - } - }, - { - loader: 'postcss-loader', - options: { - sourceMap: true - } - } + ]) ] - }, - { - test: /\.scss$/, - exclude: [ - /node_modules/, - buildRoot('styles/_exposed_variables.scss'), - buildRoot('styles/_variables.scss') - ], - use: [ - { - loader: 'raw-loader', - options: { - sourceMap: true - } - }, - { - loader: 'postcss-loader', - options: { - sourceMap: true - } - }, - { - loader: 'resolve-url-loader', - options: { - sourceMap: true - } - }, - { - loader: 'sass-loader', - options: { - sourceMap: true, - includePaths: [path.join(themePath, 'styles')] - } - }, - { - loader: 'sass-resources-loader', - options: { - resources: globalCSSImports - }, - }, - { - loader: 'string-replace-loader', - options: themeReplaceOptions - } - ] - }, - { - test: /(_exposed)?_variables.scss$/, - exclude: [/node_modules/], - use: [ - { - loader: 'css-loader', - options: { - sourceMap: true, - modules: true - } - }, - { - loader: 'postcss-loader', - options: { - sourceMap: true - } - }, - { - loader: 'resolve-url-loader', - options: { - sourceMap: true - } - }, - { - loader: 'sass-loader', - options: { - sourceMap: true, - includePaths: [path.join(themePath, 'styles')] - } - }, - { - loader: 'string-replace-loader', - options: themeReplaceOptions - } - ] - }, - { - test: /\.html$/, - loader: 'raw-loader' - } - ] - }, - plugins: [ - new CopyWebpackPlugin([{ - from: path.join(__dirname, '..', 'node_modules', '@fortawesome', 'fontawesome-free', 'webfonts'), - to: path.join('assets', 'fonts') - }, { - from: path.join(__dirname, '..', 'resources', 'images'), - to: path.join('assets', 'images') - }, { - from: path.join(__dirname, '..', 'resources', 'i18n'), - to: path.join('assets', 'i18n') } - ]) - ] }; diff --git a/webpack/webpack.server.js b/webpack/webpack.server.js index 99cdfd3b68..5e80a286a0 100644 --- a/webpack/webpack.server.js +++ b/webpack/webpack.server.js @@ -4,25 +4,27 @@ const { buildRoot } = require('./helpers'); -module.exports = { - getServerWebpackPartial: function (aot) { - const entry = aot ? buildRoot('./main.server.aot.ts') : buildRoot('./main.server.ts'); - return { - entry: entry, - output: { - filename: 'server.js' - }, - target: 'node', - externals: [nodeExternals({ - whitelist: [ - /@angular/, - /@ng/, - /angular2-text-mask/, - /ng2-file-upload/, - /angular-sortablejs/, - /sortablejs/, - /ngx/] - })], +module.exports = (env) => { + return { + getServerWebpackPartial: function (aot) { + const entry = aot ? buildRoot('./main.server.aot.ts', env) : buildRoot('./main.server.ts', env); + return { + entry: entry, + output: { + filename: 'server.js' + }, + target: 'node', + externals: [nodeExternals({ + whitelist: [ + /@angular/, + /@ng/, + /angular2-text-mask/, + /ng2-file-upload/, + /angular-sortablejs/, + /sortablejs/, + /ngx/] + })], + } } } };