@mainset/bundler-webpack 0.1.0 → 0.2.0-rc.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/webpack-config/config-fragments/common-webapp.fragment.mjs +19 -0
- package/dist/esm/webpack-config/config-fragments/common.fragment.mjs +19 -24
- package/dist/esm/webpack-config/config-fragments/csr-webapp.fragment.mjs +5 -7
- package/dist/esm/webpack-config/config-fragments/dev.fragment.mjs +27 -0
- package/dist/esm/webpack-config/config-fragments/module-rules/index.mjs +2 -0
- package/dist/esm/webpack-config/config-fragments/module-rules/module-rules.chunk.mjs +46 -0
- package/dist/esm/webpack-config/config-fragments/module-rules/module-rules.fragment.mjs +19 -0
- package/dist/esm/webpack-config/config-fragments/prod.fragment.mjs +31 -0
- package/dist/esm/webpack-config/config-fragments/ssr-webapp.fragment.mjs +8 -8
- package/dist/esm/webpack-config/dev-server.csr.config.mjs +2 -2
- package/dist/esm/webpack-config/server.ssr.config.mjs +104 -0
- package/dist/esm/webpack-config/webapp.ssr.config.mjs +6 -1
- package/package.json +22 -4
- package/src/@types/bundler.d.ts +4 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { resolveHostPackageNodeModulesPath, runtimePathById, } from '@mainset/cli/runtime';
|
|
2
|
+
import { merge } from '@mainset/toolkit-js';
|
|
3
|
+
import fs from 'fs';
|
|
4
|
+
import path from 'path';
|
|
5
|
+
import { commonWebpackConfigFragment } from './common.fragment.mjs';
|
|
6
|
+
// The entry point for Global styles
|
|
7
|
+
const cssGlobalStylesEntry = path.join(runtimePathById.src, 'styles', 'global.css');
|
|
8
|
+
const scssGlobalStylesEntry = path.join(runtimePathById.src, 'styles', 'global.scss');
|
|
9
|
+
const defaultEntry = [
|
|
10
|
+
resolveHostPackageNodeModulesPath('@mainset/bundler-webpack', '@babel/polyfill'),
|
|
11
|
+
];
|
|
12
|
+
if (fs.existsSync(cssGlobalStylesEntry))
|
|
13
|
+
defaultEntry.push(cssGlobalStylesEntry);
|
|
14
|
+
if (fs.existsSync(scssGlobalStylesEntry))
|
|
15
|
+
defaultEntry.push(scssGlobalStylesEntry);
|
|
16
|
+
const commonWebappWebpackConfigFragment = merge(commonWebpackConfigFragment, {
|
|
17
|
+
entry: defaultEntry,
|
|
18
|
+
});
|
|
19
|
+
export { commonWebappWebpackConfigFragment };
|
|
@@ -1,35 +1,19 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
1
|
+
import { runtimePathById } from '@mainset/cli/runtime';
|
|
2
|
+
import CopyWebpackPlugin from 'copy-webpack-plugin';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import { BABEL_LOADER__RULE__WEBPACK_CONFIG_FRAGMENT, FONTS__RULE_TEST_REGEX__WEBPACK_CONFIG_CHUNK, IMAGES__RULE__WEBPACK_CONFIG_FRAGMENT, } from './module-rules/index.mjs';
|
|
3
5
|
const commonWebpackConfigFragment = {
|
|
4
6
|
output: {
|
|
5
7
|
path: runtimePathById.dist,
|
|
6
8
|
},
|
|
7
9
|
module: {
|
|
8
10
|
rules: [
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
use: {
|
|
13
|
-
loader: resolveHostPackageNodeModulesPath('@mainset/bundler-webpack', 'babel-loader'),
|
|
14
|
-
options: babelConfig,
|
|
15
|
-
},
|
|
16
|
-
},
|
|
17
|
-
{
|
|
18
|
-
test: /\.(svg|png)$/,
|
|
19
|
-
type: 'asset/resource',
|
|
20
|
-
generator: {
|
|
21
|
-
filename: '[name].[hash].[ext]',
|
|
22
|
-
outputPath: 'dist/assets/images',
|
|
23
|
-
},
|
|
24
|
-
},
|
|
25
|
-
{
|
|
26
|
-
test: /\.(woff|woff2|eot|ttf|otf)$/,
|
|
27
|
-
type: 'asset/resource',
|
|
28
|
-
generator: {
|
|
11
|
+
BABEL_LOADER__RULE__WEBPACK_CONFIG_FRAGMENT,
|
|
12
|
+
IMAGES__RULE__WEBPACK_CONFIG_FRAGMENT,
|
|
13
|
+
Object.assign(Object.assign({}, FONTS__RULE_TEST_REGEX__WEBPACK_CONFIG_CHUNK), { type: 'asset/resource', generator: {
|
|
29
14
|
filename: '[name].[hash].[ext]',
|
|
30
15
|
outputPath: 'dist/assets/fonts',
|
|
31
|
-
},
|
|
32
|
-
},
|
|
16
|
+
} }),
|
|
33
17
|
],
|
|
34
18
|
},
|
|
35
19
|
resolve: {
|
|
@@ -44,5 +28,16 @@ const commonWebpackConfigFragment = {
|
|
|
44
28
|
'.tsx',
|
|
45
29
|
],
|
|
46
30
|
},
|
|
31
|
+
plugins: [
|
|
32
|
+
new CopyWebpackPlugin({
|
|
33
|
+
patterns: [
|
|
34
|
+
{
|
|
35
|
+
from: path.join(runtimePathById.root, 'public'),
|
|
36
|
+
to: path.join(runtimePathById.dist),
|
|
37
|
+
noErrorOnMissing: true, // optional: don't error if public doesn't exist
|
|
38
|
+
},
|
|
39
|
+
],
|
|
40
|
+
}),
|
|
41
|
+
],
|
|
47
42
|
};
|
|
48
43
|
export { commonWebpackConfigFragment };
|
|
@@ -1,15 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { runtimePathById } from '@mainset/cli/runtime';
|
|
2
2
|
import { merge } from '@mainset/toolkit-js';
|
|
3
3
|
import fs from 'fs';
|
|
4
4
|
import path from 'path';
|
|
5
|
-
import {
|
|
5
|
+
import { commonWebappWebpackConfigFragment } from './common-webapp.fragment.mjs';
|
|
6
|
+
// The entry point for the CSR webapp
|
|
6
7
|
const defaultEntry = path.join(runtimePathById.src, 'index.ts');
|
|
7
8
|
const csrEntry = path.join(runtimePathById.src, 'index.csr.ts');
|
|
8
9
|
const bundlerEntry = fs.existsSync(csrEntry) ? csrEntry : defaultEntry;
|
|
9
|
-
const csrWebappWebpackConfigFragment = merge(
|
|
10
|
-
entry: [
|
|
11
|
-
resolveHostPackageNodeModulesPath('@mainset/bundler-webpack', '@babel/polyfill'),
|
|
12
|
-
bundlerEntry,
|
|
13
|
-
],
|
|
10
|
+
const csrWebappWebpackConfigFragment = merge(commonWebappWebpackConfigFragment, {
|
|
11
|
+
entry: [bundlerEntry],
|
|
14
12
|
});
|
|
15
13
|
export { csrWebappWebpackConfigFragment };
|
|
@@ -1,8 +1,35 @@
|
|
|
1
|
+
import { resolveHostPackageNodeModulesPath } from '@mainset/cli/runtime';
|
|
2
|
+
import { CSS_LOADER__DEV_RULE_USE_OPTIONS__WEBPACK_CONFIG_CHUNK, CSS_MODULES__RULE_TEST_REGEX__WEBPACK_CONFIG_CHUNK, CSS_STYLES__RULE_TEST_REGEX__WEBPACK_CONFIG_CHUNK, CSS_STYLES__RULE_USE_OPTIONS__WEBPACK_CONFIG_CHUNK, } from './module-rules/index.mjs';
|
|
1
3
|
const devWebpackConfigFragment = {
|
|
2
4
|
mode: 'development',
|
|
3
5
|
output: {
|
|
4
6
|
filename: 'js/[name].js',
|
|
5
7
|
chunkFilename: 'js/[id].js',
|
|
6
8
|
},
|
|
9
|
+
module: {
|
|
10
|
+
rules: [
|
|
11
|
+
Object.assign(Object.assign({}, CSS_STYLES__RULE_TEST_REGEX__WEBPACK_CONFIG_CHUNK), { oneOf: [
|
|
12
|
+
Object.assign(Object.assign({}, CSS_MODULES__RULE_TEST_REGEX__WEBPACK_CONFIG_CHUNK), { use: [
|
|
13
|
+
// NOTE: do NOT use {style-loader} in {production} mode
|
|
14
|
+
// https://webpack.js.org/loaders/style-loader/#recommended
|
|
15
|
+
resolveHostPackageNodeModulesPath('@mainset/bundler-webpack', 'style-loader'),
|
|
16
|
+
// NOTE: by default {css-loader} transforms CSS Modules to hashed class names
|
|
17
|
+
// which is not development-friendly
|
|
18
|
+
CSS_LOADER__DEV_RULE_USE_OPTIONS__WEBPACK_CONFIG_CHUNK,
|
|
19
|
+
...CSS_STYLES__RULE_USE_OPTIONS__WEBPACK_CONFIG_CHUNK,
|
|
20
|
+
] }),
|
|
21
|
+
// Pure CSS support without CSS Modules
|
|
22
|
+
{
|
|
23
|
+
use: [
|
|
24
|
+
// NOTE: do NOT use {style-loader} in {production} mode
|
|
25
|
+
// https://webpack.js.org/loaders/style-loader/#recommended
|
|
26
|
+
resolveHostPackageNodeModulesPath('@mainset/bundler-webpack', 'style-loader'),
|
|
27
|
+
resolveHostPackageNodeModulesPath('@mainset/bundler-webpack', 'css-loader'),
|
|
28
|
+
...CSS_STYLES__RULE_USE_OPTIONS__WEBPACK_CONFIG_CHUNK,
|
|
29
|
+
],
|
|
30
|
+
},
|
|
31
|
+
] }),
|
|
32
|
+
],
|
|
33
|
+
},
|
|
7
34
|
};
|
|
8
35
|
export { devWebpackConfigFragment };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { resolveHostPackageNodeModulesPath, runtimePathById, } from '@mainset/cli/runtime';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
// RegEx patterns for matching module rules in Webpack configuration
|
|
5
|
+
const CSS_STYLES__RULE_TEST_REGEX__WEBPACK_CONFIG_CHUNK = {
|
|
6
|
+
test: /\.(sa|sc|c)ss$/,
|
|
7
|
+
};
|
|
8
|
+
const CSS_MODULES__RULE_TEST_REGEX__WEBPACK_CONFIG_CHUNK = {
|
|
9
|
+
test: /\.module\.(sa|sc|c)ss$/,
|
|
10
|
+
};
|
|
11
|
+
const FONTS__RULE_TEST_REGEX__WEBPACK_CONFIG_CHUNK = {
|
|
12
|
+
test: /\.(woff|woff2|eot|ttf|otf)$/,
|
|
13
|
+
};
|
|
14
|
+
// Use options for CSS loader rule in Webpack configuration
|
|
15
|
+
const CSS_LOADER__PROD_RULE_USE_OPTIONS__WEBPACK_CONFIG_CHUNK = {
|
|
16
|
+
loader: resolveHostPackageNodeModulesPath('@mainset/bundler-webpack', 'css-loader'),
|
|
17
|
+
};
|
|
18
|
+
const CSS_LOADER__DEV_RULE_USE_OPTIONS__WEBPACK_CONFIG_CHUNK = {
|
|
19
|
+
loader: resolveHostPackageNodeModulesPath('@mainset/bundler-webpack', 'css-loader'),
|
|
20
|
+
// NOTE: by default {css-loader} transforms CSS Modules to hashed class names
|
|
21
|
+
// which is not development-friendly
|
|
22
|
+
options: {
|
|
23
|
+
modules: {
|
|
24
|
+
// hashed class names
|
|
25
|
+
localIdentName: '[local]--[hash:base64:5]',
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
// Use options for CSS styles rule in Webpack configuration
|
|
30
|
+
const postcssConfigPath = path.join(runtimePathById.root, 'config', 'postcss.config.cjs');
|
|
31
|
+
const CSS_STYLES__RULE_USE_OPTIONS__WEBPACK_CONFIG_CHUNK = [
|
|
32
|
+
// resolveHostPackageNodeModulesPath(
|
|
33
|
+
// '@mainset/bundler-webpack',
|
|
34
|
+
// 'resolve-url-loader',
|
|
35
|
+
// ),
|
|
36
|
+
{
|
|
37
|
+
loader: resolveHostPackageNodeModulesPath('@mainset/bundler-webpack', 'postcss-loader'),
|
|
38
|
+
options: {
|
|
39
|
+
postcssOptions: {
|
|
40
|
+
config: fs.existsSync(postcssConfigPath) && postcssConfigPath,
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
resolveHostPackageNodeModulesPath('@mainset/bundler-webpack', 'sass-loader'),
|
|
45
|
+
];
|
|
46
|
+
export { CSS_LOADER__DEV_RULE_USE_OPTIONS__WEBPACK_CONFIG_CHUNK, CSS_LOADER__PROD_RULE_USE_OPTIONS__WEBPACK_CONFIG_CHUNK, CSS_MODULES__RULE_TEST_REGEX__WEBPACK_CONFIG_CHUNK, CSS_STYLES__RULE_TEST_REGEX__WEBPACK_CONFIG_CHUNK, CSS_STYLES__RULE_USE_OPTIONS__WEBPACK_CONFIG_CHUNK, FONTS__RULE_TEST_REGEX__WEBPACK_CONFIG_CHUNK, };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { resolveHostPackageNodeModulesPath } from '@mainset/cli/runtime';
|
|
2
|
+
import babelConfig from '../../../babel.config.mjs';
|
|
3
|
+
const BABEL_LOADER__RULE__WEBPACK_CONFIG_FRAGMENT = {
|
|
4
|
+
test: /\.(ts|mts|tsx)$/,
|
|
5
|
+
exclude: /node_modules/,
|
|
6
|
+
use: {
|
|
7
|
+
loader: resolveHostPackageNodeModulesPath('@mainset/bundler-webpack', 'babel-loader'),
|
|
8
|
+
options: babelConfig,
|
|
9
|
+
},
|
|
10
|
+
};
|
|
11
|
+
const IMAGES__RULE__WEBPACK_CONFIG_FRAGMENT = {
|
|
12
|
+
test: /\.(svg|png)$/,
|
|
13
|
+
type: 'asset/resource',
|
|
14
|
+
generator: {
|
|
15
|
+
filename: '[name].[hash].[ext]',
|
|
16
|
+
outputPath: 'dist/assets/images',
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
export { IMAGES__RULE__WEBPACK_CONFIG_FRAGMENT, BABEL_LOADER__RULE__WEBPACK_CONFIG_FRAGMENT, };
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
+
import { resolveHostPackageNodeModulesPath } from '@mainset/cli/runtime';
|
|
2
|
+
import MiniCssExtractPlugin from 'mini-css-extract-plugin';
|
|
1
3
|
import TerserPlugin from 'terser-webpack-plugin';
|
|
4
|
+
import { CSS_LOADER__PROD_RULE_USE_OPTIONS__WEBPACK_CONFIG_CHUNK, CSS_MODULES__RULE_TEST_REGEX__WEBPACK_CONFIG_CHUNK, CSS_STYLES__RULE_TEST_REGEX__WEBPACK_CONFIG_CHUNK, CSS_STYLES__RULE_USE_OPTIONS__WEBPACK_CONFIG_CHUNK, } from './module-rules/index.mjs';
|
|
2
5
|
const prodWebpackConfigFragment = {
|
|
3
6
|
mode: 'production',
|
|
4
7
|
output: {
|
|
@@ -20,5 +23,33 @@ const prodWebpackConfigFragment = {
|
|
|
20
23
|
},
|
|
21
24
|
},
|
|
22
25
|
},
|
|
26
|
+
module: {
|
|
27
|
+
rules: [
|
|
28
|
+
Object.assign(Object.assign({}, CSS_STYLES__RULE_TEST_REGEX__WEBPACK_CONFIG_CHUNK), { oneOf: [
|
|
29
|
+
Object.assign(Object.assign({}, CSS_MODULES__RULE_TEST_REGEX__WEBPACK_CONFIG_CHUNK), { use: [
|
|
30
|
+
MiniCssExtractPlugin.loader,
|
|
31
|
+
// NOTE: allow {css-loader} to transform CSS Modules to hashed class names
|
|
32
|
+
CSS_LOADER__PROD_RULE_USE_OPTIONS__WEBPACK_CONFIG_CHUNK,
|
|
33
|
+
...CSS_STYLES__RULE_USE_OPTIONS__WEBPACK_CONFIG_CHUNK,
|
|
34
|
+
] }),
|
|
35
|
+
// Pure CSS support without CSS Modules
|
|
36
|
+
{
|
|
37
|
+
use: [
|
|
38
|
+
MiniCssExtractPlugin.loader,
|
|
39
|
+
// NOTE: do NOT transform Global CSS class names to hashed class names
|
|
40
|
+
// as there is regular string used as class in the app code which will not be transformed
|
|
41
|
+
resolveHostPackageNodeModulesPath('@mainset/bundler-webpack', 'css-loader'),
|
|
42
|
+
...CSS_STYLES__RULE_USE_OPTIONS__WEBPACK_CONFIG_CHUNK,
|
|
43
|
+
],
|
|
44
|
+
},
|
|
45
|
+
] }),
|
|
46
|
+
],
|
|
47
|
+
},
|
|
48
|
+
plugins: [
|
|
49
|
+
new MiniCssExtractPlugin({
|
|
50
|
+
filename: 'css/[name].[chunkhash:8].min.css',
|
|
51
|
+
chunkFilename: 'css/[id].[chunkhash:8].min.css',
|
|
52
|
+
}),
|
|
53
|
+
],
|
|
23
54
|
};
|
|
24
55
|
export { prodWebpackConfigFragment };
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { runtimePathById } from '@mainset/cli/runtime';
|
|
2
2
|
import { merge } from '@mainset/toolkit-js';
|
|
3
3
|
import fs from 'fs';
|
|
4
4
|
import path from 'path';
|
|
5
|
-
import {
|
|
5
|
+
import { commonWebappWebpackConfigFragment } from './common-webapp.fragment.mjs';
|
|
6
|
+
// The entry point for the SSR webapp
|
|
6
7
|
const defaultEntry = path.join(runtimePathById.src, 'index.ts');
|
|
7
8
|
const ssrEntry = path.join(runtimePathById.src, 'index.ssr.ts');
|
|
8
9
|
const bundlerEntry = fs.existsSync(ssrEntry) ? ssrEntry : defaultEntry;
|
|
9
|
-
const ssrWebappWebpackConfigFragment = merge(
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
],
|
|
10
|
+
const ssrWebappWebpackConfigFragment = merge(
|
|
11
|
+
// NOTE: the Web App config used to compile entry point of {global.css} styles
|
|
12
|
+
commonWebappWebpackConfigFragment, {
|
|
13
|
+
entry: [bundlerEntry],
|
|
14
14
|
output: {
|
|
15
|
-
path: path.join(
|
|
15
|
+
path: path.join(commonWebappWebpackConfigFragment.output.path, 'public'),
|
|
16
16
|
},
|
|
17
17
|
});
|
|
18
18
|
export { ssrWebappWebpackConfigFragment };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { runtimePathById } from '@mainset/cli/runtime';
|
|
2
2
|
import { merge } from '@mainset/toolkit-js';
|
|
3
3
|
import csrWebappEnvBasedConfig from './webapp.csr.config.mjs';
|
|
4
|
-
const
|
|
4
|
+
const csrDevServerWebappEnvBasedConfig = merge(csrWebappEnvBasedConfig, {
|
|
5
5
|
devtool: 'inline-source-map',
|
|
6
6
|
devServer: {
|
|
7
7
|
port: process.env.PORT || 3000,
|
|
@@ -12,4 +12,4 @@ const csrServerDevConfig = merge(csrWebappEnvBasedConfig, {
|
|
|
12
12
|
hot: true,
|
|
13
13
|
},
|
|
14
14
|
});
|
|
15
|
-
export default
|
|
15
|
+
export default csrDevServerWebappEnvBasedConfig;
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { NODE_ENV, resolveHostPackageNodeModulesPath, runtimePathById, } from '@mainset/cli/runtime';
|
|
2
|
+
import { merge } from '@mainset/toolkit-js';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import { commonWebpackConfigFragment } from './config-fragments/common.fragment.mjs';
|
|
5
|
+
import { BABEL_LOADER__RULE__WEBPACK_CONFIG_FRAGMENT, CSS_LOADER__DEV_RULE_USE_OPTIONS__WEBPACK_CONFIG_CHUNK, CSS_LOADER__PROD_RULE_USE_OPTIONS__WEBPACK_CONFIG_CHUNK, CSS_MODULES__RULE_TEST_REGEX__WEBPACK_CONFIG_CHUNK, CSS_STYLES__RULE_TEST_REGEX__WEBPACK_CONFIG_CHUNK, CSS_STYLES__RULE_USE_OPTIONS__WEBPACK_CONFIG_CHUNK, FONTS__RULE_TEST_REGEX__WEBPACK_CONFIG_CHUNK, IMAGES__RULE__WEBPACK_CONFIG_FRAGMENT, } from './config-fragments/module-rules/index.mjs';
|
|
6
|
+
const nullLoaderModuleRules = [
|
|
7
|
+
FONTS__RULE_TEST_REGEX__WEBPACK_CONFIG_CHUNK,
|
|
8
|
+
].map((ruleTestRegexWebpackConfigFragment) => (Object.assign(Object.assign({}, ruleTestRegexWebpackConfigFragment), { use: resolveHostPackageNodeModulesPath('@mainset/bundler-webpack', 'null-loader') })));
|
|
9
|
+
const ssrServerCommonWebpackConfigFragment = {
|
|
10
|
+
// common config
|
|
11
|
+
resolve: commonWebpackConfigFragment.resolve,
|
|
12
|
+
// SSR server dedicated config
|
|
13
|
+
target: 'node',
|
|
14
|
+
entry: {
|
|
15
|
+
'ssr-server.config': path.join(runtimePathById.root, 'config', 'ssr-server.config.mts'),
|
|
16
|
+
},
|
|
17
|
+
output: {
|
|
18
|
+
path: path.join(runtimePathById.dist, 'private'),
|
|
19
|
+
filename: '[name].mjs',
|
|
20
|
+
library: {
|
|
21
|
+
type: 'module',
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
experiments: {
|
|
25
|
+
outputModule: true,
|
|
26
|
+
},
|
|
27
|
+
/*
|
|
28
|
+
optimization: {
|
|
29
|
+
// !IMPORTANT: {splitChunks} is designed to optimize the client-side JavaScript
|
|
30
|
+
// When bundling for SSR, splitting chunks usually doesn't make sense, and even breaks SSR — because:
|
|
31
|
+
// - The server expects a single, self-contained entry file.
|
|
32
|
+
// - Lazy-loaded chunks may not be resolvable during SSR runtime.
|
|
33
|
+
splitChunks: false,
|
|
34
|
+
},
|
|
35
|
+
*/
|
|
36
|
+
module: {
|
|
37
|
+
rules: [
|
|
38
|
+
// common config
|
|
39
|
+
BABEL_LOADER__RULE__WEBPACK_CONFIG_FRAGMENT,
|
|
40
|
+
IMAGES__RULE__WEBPACK_CONFIG_FRAGMENT,
|
|
41
|
+
// do NOT bundle in SSR mode, because they are not used during rendering on the server
|
|
42
|
+
...nullLoaderModuleRules,
|
|
43
|
+
],
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
const generateSSRCssStylesRuleWebpackConfigFragment = ({ mode }) => {
|
|
47
|
+
const CSS_LOADER__RULE_USE_OPTIONS__BY_MODE = {
|
|
48
|
+
[NODE_ENV.PRODUCTION]: CSS_LOADER__PROD_RULE_USE_OPTIONS__WEBPACK_CONFIG_CHUNK,
|
|
49
|
+
[NODE_ENV.DEVELOPMENT]: CSS_LOADER__DEV_RULE_USE_OPTIONS__WEBPACK_CONFIG_CHUNK,
|
|
50
|
+
};
|
|
51
|
+
return Object.assign(Object.assign({}, CSS_STYLES__RULE_TEST_REGEX__WEBPACK_CONFIG_CHUNK), { oneOf: [
|
|
52
|
+
Object.assign(Object.assign({}, CSS_MODULES__RULE_TEST_REGEX__WEBPACK_CONFIG_CHUNK), { use: [
|
|
53
|
+
// NOTE: allow {css-loader} to transform CSS Modules to hashed class names while rendering HTML
|
|
54
|
+
merge(CSS_LOADER__RULE_USE_OPTIONS__BY_MODE[mode], {
|
|
55
|
+
options: {
|
|
56
|
+
modules: {
|
|
57
|
+
// !IMPORTANT: attach transformed CSS Modules class names into HTML
|
|
58
|
+
// without compiling CSS inside JS file
|
|
59
|
+
exportOnlyLocals: true,
|
|
60
|
+
// - {exportOnlyLocals: true} tells css-loader to only export the mapping of class names to hashes
|
|
61
|
+
// (for use in SSR), and not to emit or bundle any CSS.
|
|
62
|
+
// - This allows your SSR code to inject the correct class names into the rendered HTML,
|
|
63
|
+
// without including or compiling CSS into the server bundle.
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
}, {
|
|
67
|
+
isSourceObjMutated: false,
|
|
68
|
+
}),
|
|
69
|
+
...CSS_STYLES__RULE_USE_OPTIONS__WEBPACK_CONFIG_CHUNK,
|
|
70
|
+
] }),
|
|
71
|
+
// Pure CSS support without CSS Modules
|
|
72
|
+
{
|
|
73
|
+
// do NOT bundle in SSR mode, because they are not used during rendering on the server
|
|
74
|
+
use: [
|
|
75
|
+
resolveHostPackageNodeModulesPath('@mainset/bundler-webpack', 'null-loader'),
|
|
76
|
+
],
|
|
77
|
+
},
|
|
78
|
+
] });
|
|
79
|
+
};
|
|
80
|
+
const ssrServerProdWebpackConfigFragment = {
|
|
81
|
+
mode: 'production',
|
|
82
|
+
module: {
|
|
83
|
+
rules: [
|
|
84
|
+
generateSSRCssStylesRuleWebpackConfigFragment({
|
|
85
|
+
mode: NODE_ENV.PRODUCTION,
|
|
86
|
+
}),
|
|
87
|
+
],
|
|
88
|
+
},
|
|
89
|
+
};
|
|
90
|
+
const ssrServerDevWebpackConfigFragment = {
|
|
91
|
+
mode: 'development',
|
|
92
|
+
module: {
|
|
93
|
+
rules: [
|
|
94
|
+
generateSSRCssStylesRuleWebpackConfigFragment({
|
|
95
|
+
mode: NODE_ENV.DEVELOPMENT,
|
|
96
|
+
}),
|
|
97
|
+
],
|
|
98
|
+
},
|
|
99
|
+
};
|
|
100
|
+
const ssrServerEnvBasedConfig = {
|
|
101
|
+
[NODE_ENV.PRODUCTION]: merge(ssrServerProdWebpackConfigFragment, ssrServerCommonWebpackConfigFragment),
|
|
102
|
+
[NODE_ENV.DEVELOPMENT]: merge(ssrServerDevWebpackConfigFragment, ssrServerCommonWebpackConfigFragment),
|
|
103
|
+
};
|
|
104
|
+
export default ssrServerEnvBasedConfig[process.env.NODE_ENV];
|
|
@@ -5,6 +5,7 @@ import path from 'path';
|
|
|
5
5
|
import { devWebpackConfigFragment } from './config-fragments/dev.fragment.mjs';
|
|
6
6
|
import { prodWebpackConfigFragment } from './config-fragments/prod.fragment.mjs';
|
|
7
7
|
import { ssrWebappWebpackConfigFragment } from './config-fragments/ssr-webapp.fragment.mjs';
|
|
8
|
+
import ssrServerEnvBasedConfig from './server.ssr.config.mjs';
|
|
8
9
|
const ssrWebappGeneralConfig = merge(ssrWebappWebpackConfigFragment, {
|
|
9
10
|
plugins: [
|
|
10
11
|
new HtmlWebpackPlugin({
|
|
@@ -17,4 +18,8 @@ const ssrWebappEnvBasedConfig = {
|
|
|
17
18
|
[NODE_ENV.PRODUCTION]: merge(prodWebpackConfigFragment, ssrWebappGeneralConfig),
|
|
18
19
|
[NODE_ENV.DEVELOPMENT]: merge(devWebpackConfigFragment, ssrWebappGeneralConfig),
|
|
19
20
|
};
|
|
20
|
-
export default
|
|
21
|
+
export default [
|
|
22
|
+
ssrServerEnvBasedConfig,
|
|
23
|
+
// NOTE: all Env Based configs declared outside {config-fragments} folder
|
|
24
|
+
ssrWebappEnvBasedConfig[process.env.NODE_ENV],
|
|
25
|
+
];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mainset/bundler-webpack",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0-rc.2",
|
|
4
4
|
"description": "Bundler for web apps",
|
|
5
5
|
"homepage": "https://github.com/mainset/dev-stack-fe/tree/main/packages/bundler-webpack",
|
|
6
6
|
"bugs": {
|
|
@@ -15,8 +15,12 @@
|
|
|
15
15
|
"type": "module",
|
|
16
16
|
"sideEffects": false,
|
|
17
17
|
"files": [
|
|
18
|
-
"dist"
|
|
18
|
+
"dist",
|
|
19
|
+
"src/@types"
|
|
19
20
|
],
|
|
21
|
+
"exports": {
|
|
22
|
+
"./global-types": "./src/@types/bundler.d.ts"
|
|
23
|
+
},
|
|
20
24
|
"dependencies": {
|
|
21
25
|
"@babel/cli": "^7.27.2",
|
|
22
26
|
"@babel/core": "^7.27.4",
|
|
@@ -25,15 +29,29 @@
|
|
|
25
29
|
"@babel/preset-react": "^7.27.1",
|
|
26
30
|
"@babel/preset-typescript": "^7.27.1",
|
|
27
31
|
"babel-loader": "^10.0.0",
|
|
32
|
+
"copy-webpack-plugin": "^13.0.0",
|
|
33
|
+
"css-loader": "^7.1.2",
|
|
28
34
|
"html-webpack-plugin": "^5.6.3",
|
|
35
|
+
"mini-css-extract-plugin": "^2.9.2",
|
|
36
|
+
"null-loader": "^4.0.1",
|
|
37
|
+
"postcss": "^8.5.6",
|
|
38
|
+
"postcss-loader": "^8.1.1",
|
|
39
|
+
"sass": "^1.89.2",
|
|
40
|
+
"sass-loader": "^16.0.5",
|
|
41
|
+
"style-loader": "^4.0.0",
|
|
29
42
|
"terser-webpack-plugin": "^5.3.14",
|
|
30
43
|
"webpack": "^5.99.9",
|
|
31
44
|
"webpack-cli": "^6.0.1",
|
|
32
45
|
"webpack-dev-server": "^5.2.2"
|
|
33
46
|
},
|
|
34
47
|
"devDependencies": {
|
|
35
|
-
"@mainset/
|
|
36
|
-
"@mainset/
|
|
48
|
+
"@mainset/cli": "^0.2.0-rc.2",
|
|
49
|
+
"@mainset/dev-stack-fe": "^0.1.1",
|
|
50
|
+
"@mainset/toolkit-js": "^0.1.0"
|
|
51
|
+
},
|
|
52
|
+
"peerDependencies": {
|
|
53
|
+
"@mainset/cli": "^0.2.0",
|
|
54
|
+
"@mainset/dev-stack-fe": "^0.1.1",
|
|
37
55
|
"@mainset/toolkit-js": "^0.1.0"
|
|
38
56
|
},
|
|
39
57
|
"scripts": {
|