This commit is contained in:
Eugene Pankov
2021-07-24 20:25:09 +02:00
parent 3de04221c2
commit 2b4d788c28
25 changed files with 1184 additions and 272 deletions

View File

@@ -2,32 +2,24 @@ const path = require('path')
const webpack = require('webpack')
const { AngularWebpackPlugin } = require('@ngtools/webpack')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const MiniCssExtractPlugin = require("mini-css-extract-plugin")
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
const htmlPluginOptions = {
hash: true,
minify: false
}
module.exports = {
target: 'web',
entry: {
index: path.resolve(__dirname, 'src/index.ts'),
terminal: path.resolve(__dirname, 'src/terminal.ts'),
},
const baseConfig = {
mode: process.env.DEV ? 'development' : 'production',
context: __dirname,
devtool: 'source-map',
output: {
path: path.join(__dirname, 'build'),
pathinfo: true,
publicPath: '/static/',
filename: '[name].js',
chunkFilename: '[name].bundle.js',
},
cache: !process.env.DEV ? false : {
type: 'filesystem',
},
resolve: {
mainFields: ['esm2015', 'browser', 'module', 'main'],
modules: [
'src/',
'node_modules/',
@@ -53,14 +45,14 @@ module.exports = {
},
{
test: /\.scss$/,
use: ['style-loader', 'css-loader', 'sass-loader'],
use: [MiniCssExtractPlugin.loader, 'css-loader', 'sass-loader'],
exclude: /component\.scss/
},
{
test: /\.(ttf|eot|otf|woff|woff2)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
type: 'asset/resource',
},
{ test: /\.css$/, use: ['css-loader', 'sass-loader'] },
{ test: /\.css$/, use: [MiniCssExtractPlugin.loader, 'css-loader', 'sass-loader'] },
{
test: /\.(jpeg|png|svg)?$/,
type: 'asset/resource',
@@ -71,12 +63,8 @@ module.exports = {
},
],
},
plugins: [
new AngularWebpackPlugin({
tsconfig: 'tsconfig.main.json',
directTemplateLoading: false,
}),
new MiniCssExtractPlugin(),
new HtmlWebpackPlugin({
template: './src/index.html',
filename: 'index.html',
@@ -91,3 +79,62 @@ module.exports = {
}),
],
}
module.exports = [
{
name: 'browser',
target: 'web',
...baseConfig,
entry: {
index: path.resolve(__dirname, 'src/index.ts'),
terminal: path.resolve(__dirname, 'src/terminal.ts'),
},
plugins: [
...baseConfig.plugins,
new AngularWebpackPlugin({
tsconfig: 'tsconfig.json',
directTemplateLoading: false,
skipCodeGeneration: false,
}),
],
output: {
path: path.join(__dirname, 'build'),
pathinfo: true,
publicPath: '/static/',
filename: '[name].js',
chunkFilename: '[name].bundle.js',
},
},
{
name: 'server',
target: 'node',
...baseConfig,
entry: {
'index.server': path.resolve(__dirname, 'src/index.server.ts'),
'server': path.resolve(__dirname, 'src/server.ts'),
},
plugins: [
...baseConfig.plugins,
new AngularWebpackPlugin({
entryModule: path.resolve(__dirname, 'src/app/app.server.module`#AppServerModule'),
mainPath: path.resolve(__dirname, 'src/index.server.ts'),
tsconfig: 'tsconfig.json',
directTemplateLoading: false,
platform: 1,
skipCodeGeneration: false,
}),
],
output: {
libraryTarget: 'commonjs',
path: path.join(__dirname, 'build-server'),
pathinfo: true,
publicPath: '/static/',
filename: '[name].js',
chunkFilename: '[name].bundle.js',
},
},
]
if (process.env.BUNDLE_ANALYZER) {
module.exports[0].plugins.push(new BundleAnalyzerPlugin())
}