@loftyshaky/shared-app 0.0.1 → 0.0.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.
Files changed (2) hide show
  1. package/js/webpack.config.js +162 -156
  2. package/package.json +1 -1
@@ -1,156 +1,162 @@
1
- const path = require('path');
2
-
3
- const shared_config = ({
4
- app_type,
5
- app_root,
6
- webpack,
7
- argv,
8
- env,
9
- TerserPlugin,
10
- MiniCssExtractPlugin,
11
- CssMinimizerPlugin,
12
- CopyWebpackPlugin,
13
- copy_patters,
14
- minimize = true,
15
- enable_anouncement,
16
- callback_begin = () => undefined,
17
- callback_done = () => undefined,
18
- }) => {
19
- const shared_path = path.join(
20
- app_root,
21
- 'node_modules',
22
- '@loftyshaky',
23
- 'shared',
24
- 'scss',
25
- 'shared',
26
- );
27
- const paths = {
28
- ts: path.join(app_root, 'src', 'ts'),
29
- embed: path.join(shared_path, 'embed'),
30
- themes: path.join(shared_path, 'themes', 'general'),
31
- };
32
-
33
- const external_copy_patterns = copy_patters || [];
34
- const copy_patterns_final = [
35
- ...external_copy_patterns,
36
- ...[
37
- {
38
- from: path.join(app_root, 'node_modules', '@loftyshaky', 'shared', 'html'),
39
- noErrorOnMissing: true,
40
- globOptions: {
41
- ignore: enable_anouncement ? [] : ['**/announcement.html'],
42
- },
43
- },
44
- {
45
- from: path.join(app_root, 'src', 'html'),
46
- },
47
- ],
48
- ];
49
-
50
- if (app_type === 'app') {
51
- copy_patterns_final.push({
52
- from: path.join(app_root, 'src', 'icons'),
53
- });
54
-
55
- copy_patterns_final.push({ from: path.join(app_root, 'package.json') });
56
- }
57
-
58
- if (app_type === 'ext') {
59
- copy_patterns_final.push(
60
- {
61
- from: path.join(app_root, 'src', 'icons', 'all'),
62
- },
63
- {
64
- from: path.join(app_root, 'src', 'icons', env.browser),
65
- },
66
- );
67
- }
68
-
69
- return {
70
- entry: {
71
- ...(enable_anouncement && {
72
- announcement: path.join(paths.ts, 'announcement', 'announcement.ts'),
73
- }),
74
- font_face: path.join(paths.embed, 'font_face.scss'),
75
- no_tr: path.join(paths.embed, 'no_tr.scss'),
76
- error: path.join(paths.embed, 'error.scss'),
77
- loading_screen: path.join(paths.embed, 'loading_screen.scss'),
78
- ...(enable_anouncement && {
79
- announcement_css: path.join(
80
- app_root,
81
- 'node_modules',
82
- '@loftyshaky',
83
- 'shared',
84
- 'scss',
85
- 'announcement',
86
- 'index.scss',
87
- ),
88
- }),
89
- light_theme: path.join(paths.themes, 'light_theme.scss'),
90
- dark_theme: path.join(paths.themes, 'dark_theme.scss'),
91
- very_dark_theme: path.join(paths.themes, 'very_dark_theme.scss'),
92
- },
93
- output: {
94
- filename: '[name].js',
95
- chunkFilename: 'chunks/[name].js',
96
- path: path.join(app_root, 'dist'),
97
- publicPath: '',
98
- },
99
- resolve: {
100
- alias: {
101
- shared: path.join(paths.ts, 'shared'),
102
- ...(app_type === 'ext' && {
103
- background: path.join(paths.ts, 'background'),
104
- settings: path.join(paths.ts, 'settings'),
105
- content_script: path.join(paths.ts, 'content_script'),
106
- }),
107
- ...(enable_anouncement && {
108
- announcement: path.join(paths.ts, 'announcement'),
109
- }),
110
- },
111
- extensions: ['.js', '.jsx', '.ts', '.tsx'],
112
- },
113
- module: {
114
- rules: [
115
- {
116
- test: /\.(ts|tsx)$/,
117
- loader: 'ts-loader',
118
- },
119
- {
120
- test: /\.(scss|css)$/,
121
- use: [MiniCssExtractPlugin.loader, 'css-loader', 'sass-loader'],
122
- },
123
- {
124
- test: /\.svg$/,
125
- use: ['@svgr/webpack'],
126
- },
127
- ],
128
- },
129
- plugins: [
130
- new webpack.ProgressPlugin(),
131
- new MiniCssExtractPlugin(),
132
- new CopyWebpackPlugin({
133
- patterns: copy_patterns_final,
134
- }),
135
- {
136
- apply: (compiler) => {
137
- compiler.hooks.initialize.tap('initialize', callback_begin);
138
- compiler.hooks.done.tap('done', callback_done);
139
- },
140
- },
141
- ],
142
- target: 'web',
143
- devtool: false,
144
- optimization: {
145
- minimize: minimize && argv.mode === 'production',
146
- minimizer: [new TerserPlugin(), new CssMinimizerPlugin()],
147
- sideEffects: argv.mode === 'production',
148
- },
149
- performance: {
150
- maxEntrypointSize: 52428800,
151
- maxAssetSize: 52428800,
152
- },
153
- };
154
- };
155
-
156
- module.exports = { shared_config };
1
+ const path = require('path');
2
+
3
+ const fs = require('fs-extra');
4
+
5
+ const shared_config = ({
6
+ app_type,
7
+ app_root,
8
+ webpack,
9
+ argv,
10
+ env,
11
+ TerserPlugin,
12
+ MiniCssExtractPlugin,
13
+ CssMinimizerPlugin,
14
+ CopyWebpackPlugin,
15
+ copy_patters,
16
+ minimize = true,
17
+ enable_anouncement,
18
+ callback_begin = () => undefined,
19
+ callback_done = () => undefined,
20
+ }) => {
21
+ const package_json = fs.readJSONSync(path.join(app_root, 'package.json'));
22
+ const shared_app_is_added_as_dep = package_json.dependencies['@loftyshaky/shared-app'];
23
+
24
+ const shared_path = path.join(
25
+ app_root,
26
+ 'node_modules',
27
+ '@loftyshaky',
28
+ `shared${shared_app_is_added_as_dep ? '-app' : ''}`,
29
+ 'scss',
30
+ 'shared',
31
+ );
32
+
33
+ const paths = {
34
+ ts: path.join(app_root, 'src', 'ts'),
35
+ embed: path.join(shared_path, 'embed'),
36
+ themes: path.join(shared_path, 'themes', 'general'),
37
+ };
38
+
39
+ const external_copy_patterns = copy_patters || [];
40
+ const copy_patterns_final = [
41
+ ...external_copy_patterns,
42
+ ...[
43
+ {
44
+ from: path.join(app_root, 'node_modules', '@loftyshaky', 'shared', 'html'),
45
+ noErrorOnMissing: true,
46
+ globOptions: {
47
+ ignore: enable_anouncement ? [] : ['**/announcement.html'],
48
+ },
49
+ },
50
+ {
51
+ from: path.join(app_root, 'src', 'html'),
52
+ },
53
+ ],
54
+ ];
55
+
56
+ if (app_type === 'app') {
57
+ copy_patterns_final.push({
58
+ from: path.join(app_root, 'src', 'icons'),
59
+ });
60
+
61
+ copy_patterns_final.push({ from: path.join(app_root, 'package.json') });
62
+ }
63
+
64
+ if (app_type === 'ext') {
65
+ copy_patterns_final.push(
66
+ {
67
+ from: path.join(app_root, 'src', 'icons', 'all'),
68
+ },
69
+ {
70
+ from: path.join(app_root, 'src', 'icons', env.browser),
71
+ },
72
+ );
73
+ }
74
+
75
+ return {
76
+ entry: {
77
+ ...(enable_anouncement && {
78
+ announcement: path.join(paths.ts, 'announcement', 'announcement.ts'),
79
+ }),
80
+ font_face: path.join(paths.embed, 'font_face.scss'),
81
+ no_tr: path.join(paths.embed, 'no_tr.scss'),
82
+ error: path.join(paths.embed, 'error.scss'),
83
+ loading_screen: path.join(paths.embed, 'loading_screen.scss'),
84
+ ...(enable_anouncement && {
85
+ announcement_css: path.join(
86
+ app_root,
87
+ 'node_modules',
88
+ '@loftyshaky',
89
+ 'shared',
90
+ 'scss',
91
+ 'announcement',
92
+ 'index.scss',
93
+ ),
94
+ }),
95
+ light_theme: path.join(paths.themes, 'light_theme.scss'),
96
+ dark_theme: path.join(paths.themes, 'dark_theme.scss'),
97
+ very_dark_theme: path.join(paths.themes, 'very_dark_theme.scss'),
98
+ },
99
+ output: {
100
+ filename: '[name].js',
101
+ chunkFilename: 'chunks/[name].js',
102
+ path: path.join(app_root, 'dist'),
103
+ publicPath: '',
104
+ },
105
+ resolve: {
106
+ alias: {
107
+ shared: path.join(paths.ts, 'shared'),
108
+ ...(app_type === 'ext' && {
109
+ background: path.join(paths.ts, 'background'),
110
+ settings: path.join(paths.ts, 'settings'),
111
+ content_script: path.join(paths.ts, 'content_script'),
112
+ }),
113
+ ...(enable_anouncement && {
114
+ announcement: path.join(paths.ts, 'announcement'),
115
+ }),
116
+ },
117
+ extensions: ['.js', '.jsx', '.ts', '.tsx'],
118
+ },
119
+ module: {
120
+ rules: [
121
+ {
122
+ test: /\.(ts|tsx)$/,
123
+ loader: 'ts-loader',
124
+ },
125
+ {
126
+ test: /\.(scss|css)$/,
127
+ use: [MiniCssExtractPlugin.loader, 'css-loader', 'sass-loader'],
128
+ },
129
+ {
130
+ test: /\.svg$/,
131
+ use: ['@svgr/webpack'],
132
+ },
133
+ ],
134
+ },
135
+ plugins: [
136
+ new webpack.ProgressPlugin(),
137
+ new MiniCssExtractPlugin(),
138
+ new CopyWebpackPlugin({
139
+ patterns: copy_patterns_final,
140
+ }),
141
+ {
142
+ apply: (compiler) => {
143
+ compiler.hooks.initialize.tap('initialize', callback_begin);
144
+ compiler.hooks.done.tap('done', callback_done);
145
+ },
146
+ },
147
+ ],
148
+ target: 'web',
149
+ devtool: false,
150
+ optimization: {
151
+ minimize: minimize && argv.mode === 'production',
152
+ minimizer: [new TerserPlugin(), new CssMinimizerPlugin()],
153
+ sideEffects: argv.mode === 'production',
154
+ },
155
+ performance: {
156
+ maxEntrypointSize: 52428800,
157
+ maxAssetSize: 52428800,
158
+ },
159
+ };
160
+ };
161
+
162
+ module.exports = { shared_config };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@loftyshaky/shared-app",
3
3
  "description": "-",
4
- "version": "0.0.1",
4
+ "version": "0.0.2",
5
5
  "author": "loftyshaky",
6
6
  "license": "MIT",
7
7
  "repository": {