removed node env variable

This commit is contained in:
lotte
2019-06-05 14:25:58 +02:00
parent 5a47c2f4a7
commit ed128d1f17
8 changed files with 273 additions and 265 deletions

View File

@@ -157,7 +157,7 @@ module.exports = {
}
},
theme: {
name: 'default',
cssClass: 'default',
name: 'mantis',
cssClass: 'mantis',
}
};

View File

@@ -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",

View File

@@ -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;
};

View File

@@ -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 =
{

View File

@@ -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
}
};

View File

@@ -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'
})
]
};
}

View File

@@ -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')
}
])
]
};

View File

@@ -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/]
})],
}
}
}
};