@mainset/bundler-webpack 0.1.0

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/LICENSE ADDED
@@ -0,0 +1,2 @@
1
+ This work is licensed under the Creative Commons Attribution-NonCommercial 4.0 International License.
2
+ To view a copy of this license, visit http://creativecommons.org/licenses/by-nc/4.0/
@@ -0,0 +1,21 @@
1
+ const babelConfig = {
2
+ presets: [
3
+ [
4
+ '@babel/preset-env',
5
+ {
6
+ targets: {
7
+ node: 'current',
8
+ chrome: '60',
9
+ firefox: '60',
10
+ safari: '11.1',
11
+ edge: '17',
12
+ ie: '11',
13
+ },
14
+ },
15
+ ],
16
+ '@babel/preset-react',
17
+ '@babel/preset-typescript',
18
+ ],
19
+ plugins: [],
20
+ };
21
+ export default babelConfig;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,48 @@
1
+ import { resolveHostPackageNodeModulesPath, runtimePathById, } from '@mainset/cli/runtime';
2
+ import babelConfig from '../../babel.config.mjs';
3
+ const commonWebpackConfigFragment = {
4
+ output: {
5
+ path: runtimePathById.dist,
6
+ },
7
+ module: {
8
+ rules: [
9
+ {
10
+ test: /\.(ts|tsx)$/,
11
+ exclude: /node_modules/,
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: {
29
+ filename: '[name].[hash].[ext]',
30
+ outputPath: 'dist/assets/fonts',
31
+ },
32
+ },
33
+ ],
34
+ },
35
+ resolve: {
36
+ modules: [runtimePathById.root, 'node_modules'],
37
+ extensions: [
38
+ // Default for {extensions} key: https://webpack.js.org/configuration/resolve/#resolveloader
39
+ '.js',
40
+ '.mjs',
41
+ '.json',
42
+ // Extra / custom
43
+ '.ts',
44
+ '.tsx',
45
+ ],
46
+ },
47
+ };
48
+ export { commonWebpackConfigFragment };
@@ -0,0 +1,15 @@
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
+ const defaultEntry = path.join(runtimePathById.src, 'index.ts');
7
+ const csrEntry = path.join(runtimePathById.src, 'index.csr.ts');
8
+ const bundlerEntry = fs.existsSync(csrEntry) ? csrEntry : defaultEntry;
9
+ const csrWebappWebpackConfigFragment = merge(commonWebpackConfigFragment, {
10
+ entry: [
11
+ resolveHostPackageNodeModulesPath('@mainset/bundler-webpack', '@babel/polyfill'),
12
+ bundlerEntry,
13
+ ],
14
+ });
15
+ export { csrWebappWebpackConfigFragment };
@@ -0,0 +1,8 @@
1
+ const devWebpackConfigFragment = {
2
+ mode: 'development',
3
+ output: {
4
+ filename: 'js/[name].js',
5
+ chunkFilename: 'js/[id].js',
6
+ },
7
+ };
8
+ export { devWebpackConfigFragment };
@@ -0,0 +1,24 @@
1
+ import TerserPlugin from 'terser-webpack-plugin';
2
+ const prodWebpackConfigFragment = {
3
+ mode: 'production',
4
+ output: {
5
+ // - Use [contenthash] (or [chunkhash]) instead of [hash] for better long-term caching.
6
+ // - [hash] is for the whole build, so any change invalidates all files.
7
+ filename: 'js/[name].[chunkhash:8].min.js',
8
+ chunkFilename: 'js/[id].[chunkhash:8].min.js',
9
+ },
10
+ optimization: {
11
+ minimizer: [new TerserPlugin()],
12
+ // https://webpack.js.org/plugins/split-chunks-plugin/#split-chunks-example-2
13
+ splitChunks: {
14
+ cacheGroups: {
15
+ commons: {
16
+ test: /[\\/]node_modules[\\/]/,
17
+ name: 'vendors',
18
+ chunks: 'all',
19
+ },
20
+ },
21
+ },
22
+ },
23
+ };
24
+ export { prodWebpackConfigFragment };
@@ -0,0 +1,18 @@
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
+ const defaultEntry = path.join(runtimePathById.src, 'index.ts');
7
+ const ssrEntry = path.join(runtimePathById.src, 'index.ssr.ts');
8
+ const bundlerEntry = fs.existsSync(ssrEntry) ? ssrEntry : defaultEntry;
9
+ const ssrWebappWebpackConfigFragment = merge(commonWebpackConfigFragment, {
10
+ entry: [
11
+ resolveHostPackageNodeModulesPath('@mainset/bundler-webpack', '@babel/polyfill'),
12
+ bundlerEntry,
13
+ ],
14
+ output: {
15
+ path: path.join(commonWebpackConfigFragment.output.path, 'public'),
16
+ },
17
+ });
18
+ export { ssrWebappWebpackConfigFragment };
@@ -0,0 +1,15 @@
1
+ import { runtimePathById } from '@mainset/cli/runtime';
2
+ import { merge } from '@mainset/toolkit-js';
3
+ import csrWebappEnvBasedConfig from './webapp.csr.config.mjs';
4
+ const csrServerDevConfig = merge(csrWebappEnvBasedConfig, {
5
+ devtool: 'inline-source-map',
6
+ devServer: {
7
+ port: process.env.PORT || 3000,
8
+ static: {
9
+ directory: runtimePathById.root,
10
+ },
11
+ historyApiFallback: true,
12
+ hot: true,
13
+ },
14
+ });
15
+ export default csrServerDevConfig;
@@ -0,0 +1,19 @@
1
+ import { NODE_ENV, runtimePathById } from '@mainset/cli/runtime';
2
+ import { merge } from '@mainset/toolkit-js';
3
+ import HtmlWebpackPlugin from 'html-webpack-plugin';
4
+ import path from 'path';
5
+ import { csrWebappWebpackConfigFragment } from './config-fragments/csr-webapp.fragment.mjs';
6
+ import { devWebpackConfigFragment } from './config-fragments/dev.fragment.mjs';
7
+ import { prodWebpackConfigFragment } from './config-fragments/prod.fragment.mjs';
8
+ const csrWebappGeneralConfig = merge(csrWebappWebpackConfigFragment, {
9
+ plugins: [
10
+ new HtmlWebpackPlugin({
11
+ template: path.join(runtimePathById.src, 'index.template.html'),
12
+ }),
13
+ ],
14
+ });
15
+ const csrWebappEnvBasedConfig = {
16
+ [NODE_ENV.PRODUCTION]: merge(prodWebpackConfigFragment, csrWebappGeneralConfig),
17
+ [NODE_ENV.DEVELOPMENT]: merge(devWebpackConfigFragment, csrWebappGeneralConfig),
18
+ };
19
+ export default csrWebappEnvBasedConfig[process.env.NODE_ENV];
@@ -0,0 +1,20 @@
1
+ import { NODE_ENV, runtimePathById } from '@mainset/cli/runtime';
2
+ import { merge } from '@mainset/toolkit-js';
3
+ import HtmlWebpackPlugin from 'html-webpack-plugin';
4
+ import path from 'path';
5
+ import { devWebpackConfigFragment } from './config-fragments/dev.fragment.mjs';
6
+ import { prodWebpackConfigFragment } from './config-fragments/prod.fragment.mjs';
7
+ import { ssrWebappWebpackConfigFragment } from './config-fragments/ssr-webapp.fragment.mjs';
8
+ const ssrWebappGeneralConfig = merge(ssrWebappWebpackConfigFragment, {
9
+ plugins: [
10
+ new HtmlWebpackPlugin({
11
+ template: path.join(runtimePathById.src, 'index.template.html'),
12
+ filename: 'server.html',
13
+ }),
14
+ ],
15
+ });
16
+ const ssrWebappEnvBasedConfig = {
17
+ [NODE_ENV.PRODUCTION]: merge(prodWebpackConfigFragment, ssrWebappGeneralConfig),
18
+ [NODE_ENV.DEVELOPMENT]: merge(devWebpackConfigFragment, ssrWebappGeneralConfig),
19
+ };
20
+ export default ssrWebappEnvBasedConfig[process.env.NODE_ENV];
@@ -0,0 +1 @@
1
+ export {};
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "@mainset/bundler-webpack",
3
+ "version": "0.1.0",
4
+ "description": "Bundler for web apps",
5
+ "homepage": "https://github.com/mainset/dev-stack-fe/tree/main/packages/bundler-webpack",
6
+ "bugs": {
7
+ "url": "https://github.com/mainset/dev-stack-fe/issues"
8
+ },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "https://github.com/mainset/dev-stack-fe.git"
12
+ },
13
+ "license": "CC-BY-NC-4.0",
14
+ "author": "yevhen uzhva",
15
+ "type": "module",
16
+ "sideEffects": false,
17
+ "files": [
18
+ "dist"
19
+ ],
20
+ "dependencies": {
21
+ "@babel/cli": "^7.27.2",
22
+ "@babel/core": "^7.27.4",
23
+ "@babel/polyfill": "^7.12.1",
24
+ "@babel/preset-env": "^7.27.2",
25
+ "@babel/preset-react": "^7.27.1",
26
+ "@babel/preset-typescript": "^7.27.1",
27
+ "babel-loader": "^10.0.0",
28
+ "html-webpack-plugin": "^5.6.3",
29
+ "terser-webpack-plugin": "^5.3.14",
30
+ "webpack": "^5.99.9",
31
+ "webpack-cli": "^6.0.1",
32
+ "webpack-dev-server": "^5.2.2"
33
+ },
34
+ "devDependencies": {
35
+ "@mainset/dev-stack-fe": "^0.1.0",
36
+ "@mainset/cli": "^0.1.0",
37
+ "@mainset/toolkit-js": "^0.1.0"
38
+ },
39
+ "scripts": {
40
+ "build": "ms-cli source-code --exec compile",
41
+ "dev": "cross-env NODE_ENV=development ms-cli source-code --exec watch"
42
+ }
43
+ }