@pixolith/webpack-sw6-config 7.5.0 → 8.0.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/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
  ### Install
6
6
 
7
7
  ```bash
8
- npm install @pixolith/webpack-sw6-config--save-dev
8
+ npm install @pixolith/webpack-sw6-config --save-dev
9
9
  ```
10
10
 
11
11
  ### Require the plugin
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@pixolith/webpack-sw6-config",
3
3
  "public": true,
4
- "version": "7.5.0",
4
+ "version": "8.0.0",
5
5
  "description": "",
6
6
  "main": "src/index.js",
7
7
  "scripts": {},
@@ -21,26 +21,28 @@
21
21
  "url": "https://github.com/pixolith/webpack-plugins/issues"
22
22
  },
23
23
  "homepage": "https://github.com/pixolith/webpack-plugins/tree/master/packages/webpack-hook-plugin/#readme",
24
- "gitHead": "ce1a0dfc319927e3bc9462e460a0c32873471a5e",
24
+ "gitHead": "97830e50cddc91762ad93716771e0d67a6ed2e03",
25
25
  "dependencies": {
26
- "@babel/core": "^7.22.1",
27
- "@babel/eslint-parser": "^7.21.8",
26
+ "@babel/cli": "7.23.4",
27
+ "@babel/core": "^7.23.7",
28
+ "@babel/eslint-parser": "^7.23.3",
28
29
  "@babel/plugin-proposal-class-properties": "^7.18.6",
29
30
  "@babel/plugin-proposal-object-rest-spread": "^7.20.7",
30
31
  "@babel/plugin-proposal-optional-chaining": "^7.21.0",
31
32
  "@babel/plugin-syntax-dynamic-import": "^7.8.3",
32
33
  "@babel/plugin-transform-classes": "^7.21.0",
33
34
  "@babel/plugin-transform-runtime": "^7.22.4",
34
- "@babel/preset-env": "^7.22.4",
35
- "@babel/preset-typescript": "^7.21.5",
36
- "@pixolith/eslint-config-sw6": "^7.2.0",
37
- "@pixolith/external-svg-sprite-loader": "^7.3.0",
38
- "@pixolith/stylelint-config-standard": "^7.2.0",
39
- "@pixolith/webpack-assets-copy-plugin": "^7.1.0",
40
- "@pixolith/webpack-filename-linter-plugin": "^7.0.0",
41
- "@pixolith/webpack-hook-plugin": "^7.0.0",
42
- "@pixolith/webpack-twig-assets-emitter-plugin": "^7.0.0",
43
- "@pixolith/webpack-watcher": "^7.0.0",
35
+ "@babel/preset-env": "7.23.7",
36
+ "@babel/preset-typescript": "7.23.3",
37
+ "@pixolith/eslint-config-sw6": "^8.0.0",
38
+ "@pixolith/external-svg-sprite-loader": "^8.0.0",
39
+ "@pixolith/stylelint-config-standard": "^8.0.0",
40
+ "@pixolith/webpack-assets-copy-plugin": "^8.0.0",
41
+ "@pixolith/webpack-filename-linter-plugin": "^8.0.0",
42
+ "@pixolith/webpack-hook-plugin": "^8.0.0",
43
+ "@pixolith/webpack-twig-assets-emitter-plugin": "^8.0.0",
44
+ "@pixolith/webpack-watcher": "^8.0.0",
45
+ "@swc/core": "^1.7.0",
44
46
  "autoprefixer": "^10.4.14",
45
47
  "babel-loader": "^9.1.2",
46
48
  "change-case": "^4.1.2",
@@ -2,9 +2,12 @@ module.exports = {
2
2
  presets: [
3
3
  ['@babel/preset-env', {
4
4
  useBuiltIns: 'entry',
5
- corejs: '3.27',
5
+ corejs: '3.34.0',
6
6
  bugfixes: true,
7
7
  }],
8
8
  '@babel/preset-typescript',
9
- ]
9
+ ],
10
+ plugins: [
11
+ ['@babel/plugin-proposal-decorators', { version: '2023-01' }],
12
+ ],
10
13
  };
package/src/index.js CHANGED
@@ -4,7 +4,6 @@ const dev = require('./webpack.config.dev');
4
4
  const administration = require('./webpack.config.administration');
5
5
  const isProd = process.env.NODE_ENV === 'production';
6
6
  const pkg = require('./../package.json');
7
- const isModern = process.env.MODE === 'modern';
8
7
  const watcher = require('@pixolith/webpack-watcher');
9
8
  const { merge } = require('webpack-merge');
10
9
  const Consola = require('consola');
@@ -16,7 +15,6 @@ const setup = () => {
16
15
  watcher.run();
17
16
  console.table({
18
17
  isProd: isProd,
19
- isModern: isModern,
20
18
  pluginPath: process.env.PLUGIN_PATH,
21
19
  vendorPath: process.env.VENDOR_PATH,
22
20
  publicPath: process.env.PUBLIC_PATH,
@@ -1,15 +1,11 @@
1
- module.exports = ({ file, options, env }) => {
2
- return {
3
- plugins: {
4
- // to edit target browsers: use "browserslist" field in package.json
5
- autoprefixer: {
6
- env: options.mode + (options.isModern ? ':modern' : ''),
7
- },
8
- 'postcss-pxtorem': {
9
- rootValue: 16,
10
- unitPrecision: 5,
11
- propList: ['*']
12
- }
13
- },
14
- };
1
+ module.exports = {
2
+ 'plugins': {
3
+ // to edit target browsers: use "browserslist" field in package.json
4
+ 'autoprefixer': {},
5
+ 'postcss-pxtorem': {
6
+ rootValue: 16,
7
+ unitPrecision: 5,
8
+ propList: ['*']
9
+ }
10
+ },
15
11
  };
@@ -1,13 +1,15 @@
1
1
  const Path = require('path'),
2
2
  Fs = require('fs'),
3
+ Entry = require('webpack-glob-entry'),
3
4
  privatePath = process.env.PLUGIN_PATH,
4
- changeCase = require('change-case'),
5
- entry = require('webpack-glob-entry'),
5
+ vendorPath = process.env.VENDOR_PATH,
6
6
  publicPath = process.env.PUBLIC_PATH,
7
- spritePath = process.env.SPRITE_PATH ?? 'custom/plugins/PxswTheme/src/Resources/views/administration',
7
+ spritePath = process.env.SPRITE_PATH ?? 'custom/static-plugins/PxswTheme/src/Resources/views/administration',
8
+ isProd = process.env.NODE_ENV === 'production',
9
+ ChangeCase = require('change-case'),
8
10
  MiniCssExtractPlugin = require('mini-css-extract-plugin'),
11
+ Consola = require('consola'),
9
12
  AssetsCopyPlugin = require('@pixolith/webpack-assets-copy-plugin'),
10
- isProd = process.env.NODE_ENV === 'production',
11
13
  SvgStorePlugin = require('@pixolith/external-svg-sprite-loader'),
12
14
  HookPlugin = require('@pixolith/webpack-hook-plugin'),
13
15
  outputPath = Path.resolve(process.cwd(), publicPath),
@@ -17,25 +19,51 @@ const Path = require('path'),
17
19
  filename: (chunkData) => {
18
20
  let pluginName = chunkData.chunk.name
19
21
  .toLowerCase()
20
- .replace('vendor-', '');
22
+ .replace('vendor-', '')
23
+ .replace('pxsw-pxsw-', 'pxsw-');
21
24
  return `${pluginName.replace(
22
25
  /-/g,
23
26
  '',
24
27
  )}/administration/js/${pluginName}.js`;
25
- },
28
+ }
29
+ },
30
+ miniCssChunksConfig = {
31
+ filename: (chunkData) => {
32
+ let pluginName = chunkData.chunk.name
33
+ .toLowerCase()
34
+ .replace('vendor-', '')
35
+ .replace('pxsw-pxsw-', 'pxsw-');
36
+ return `${pluginName.replace(
37
+ /-/g,
38
+ '',
39
+ )}/administration/css/${pluginName}.css`;
40
+ }
26
41
  }
27
42
 
28
43
  module.exports = {
29
44
  entry: () => {
30
- let entriesPlugins = entry(
45
+ let entriesPlugins = Entry(
31
46
  (filePath) =>
32
- changeCase.paramCase(
47
+ ChangeCase.paramCase(
33
48
  filePath.match(/plugins\/(Pxsw[\w]*)\//)[1],
34
49
  ),
35
50
  Path.resolve(privatePath, 'index.js'),
36
51
  );
37
52
 
38
- return { ...entriesPlugins };
53
+ let entriesVendor = Entry(
54
+ (filePath) =>
55
+ ChangeCase.paramCase(
56
+ filePath.match(/(vendor\/pxsw\/[\w-]*)\//)[1],
57
+ ),
58
+ Path.resolve(vendorPath, 'index.js'),
59
+ );
60
+
61
+ if (process.env.DEBUG) {
62
+ Consola.info('[DEBUG]: Webpack entry points:');
63
+ Consola.info({...entriesPlugins, ...entriesVendor});
64
+ }
65
+
66
+ return {...entriesPlugins, ...entriesVendor};
39
67
  },
40
68
  module: {
41
69
  // loader order is from right to left or from bottom to top depending on the notation but basicly always reverse
@@ -150,32 +178,6 @@ module.exports = {
150
178
  callback();
151
179
  },
152
180
  }),
153
- new AssetsCopyPlugin({
154
- includes: ['js', 'css'],
155
- ignoreFiles: [/[-\w.]*.hot-update.js/, /sprite\/sprite_uses.svg/],
156
- files: [
157
- {
158
- from: publicPath,
159
- to: 'custom/$pluginFolder/$plugin/src/Resources/public',
160
- replace: async (fromPath, toPath) => {
161
- let pluginName = changeCase.pascalCase(
162
- Path.basename(fromPath).replace(
163
- Path.extname(fromPath),
164
- '',
165
- ),
166
- );
167
-
168
- const pluginOrStaticPlugin = await Fs.existsSync('custom/plugins/$plugin/src'.replace('$plugin', pluginName));
169
-
170
- let pluginFolder = pluginOrStaticPlugin ? 'plugins' : 'static-plugins';
171
-
172
- toPath = toPath.replace('$pluginFolder', pluginFolder);
173
- toPath = toPath.replace('$plugin', pluginName);
174
- return toPath;
175
- },
176
- },
177
- ],
178
- }),
179
181
 
180
182
  new SvgStorePlugin({
181
183
  sprite: {
@@ -187,8 +189,37 @@ module.exports = {
187
189
  },
188
190
  }),
189
191
 
190
- new MiniCssExtractPlugin(),
191
- ],
192
+ new MiniCssExtractPlugin(miniCssChunksConfig),
193
+ ].concat(
194
+ isProd ?
195
+ new AssetsCopyPlugin({
196
+ includes: ['js', 'css'],
197
+ ignoreFiles: [/[-\w.]*.hot-update.js/, /sprite\/sprite_uses.svg/],
198
+ files: [
199
+ {
200
+ from: publicPath,
201
+ to: '$pluginPath/$plugin/src/Resources/public',
202
+ replace: async (fromPath, toPath) => {
203
+ let pluginName = ChangeCase.pascalCase(
204
+ Path.basename(fromPath).replace(
205
+ Path.extname(fromPath),
206
+ '',
207
+ ),
208
+ );
209
+
210
+ let isPlugin = await Fs.existsSync(`custom/plugins/${pluginName}/src`),
211
+ isStaticPlugin = await Fs.existsSync(`custom/static-plugins/${pluginName}/src`);
212
+
213
+ let pluginFolder = isPlugin ? 'custom/plugins' : (isStaticPlugin ? 'custom/static-plugins' : 'vendor/pxsw');
214
+
215
+ toPath = toPath.replace('$pluginPath', pluginFolder);
216
+ toPath = toPath.replace('$plugin', pluginName);
217
+ return toPath;
218
+ },
219
+ },
220
+ ],
221
+ }) : [],
222
+ ),
192
223
 
193
224
  optimization: {
194
225
  splitChunks: false,
@@ -1,9 +1,8 @@
1
1
  const webpack = require('webpack'),
2
2
  Path = require('path'),
3
3
  Consola = require('consola'),
4
- fs = require('fs'),
4
+ Fs = require('fs'),
5
5
  ASSET_URL = process.env.ASSET_URL || '/',
6
- StyleLintPlugin = require('stylelint-webpack-plugin'),
7
6
  isProd = process.env.NODE_ENV === 'production',
8
7
  privatePath = process.env.PLUGIN_PATH,
9
8
  MiniCssExtractPlugin = require('mini-css-extract-plugin'),
@@ -13,7 +12,7 @@ const webpack = require('webpack'),
13
12
  watcher = require('@pixolith/webpack-watcher'),
14
13
  Glob = require('glob'),
15
14
  HookPlugin = require('@pixolith/webpack-hook-plugin'),
16
- sass = require('sass'),
15
+ Sass = require('sass'),
17
16
  TimeFixPlugin = require('time-fix-plugin');
18
17
 
19
18
  module.exports = {
@@ -68,7 +67,7 @@ module.exports = {
68
67
  additionalData: `$asset_url: '${ASSET_URL}';`,
69
68
  sassOptions: {
70
69
  quietDeps: true,
71
- logger: sass.Logger.silent,
70
+ logger: Sass.Logger.silent,
72
71
  },
73
72
  },
74
73
  },
@@ -120,19 +119,19 @@ module.exports = {
120
119
  ? {
121
120
  type: 'https',
122
121
  options: {
123
- ca: fs.readFileSync(
122
+ ca: Fs.readFileSync(
124
123
  Path.join(
125
124
  process.cwd() +
126
125
  '/.ddev/ssl/_wildcard.px-staging.de+1-client.pem',
127
126
  ),
128
127
  ),
129
- key: fs.readFileSync(
128
+ key: Fs.readFileSync(
130
129
  Path.join(
131
130
  process.cwd() +
132
131
  '/.ddev/ssl/_wildcard.px-staging.de+1-key.pem',
133
132
  ),
134
133
  ),
135
- cert: fs.readFileSync(
134
+ cert: Fs.readFileSync(
136
135
  Path.join(
137
136
  process.cwd() +
138
137
  '/.ddev/ssl/_wildcard.px-staging.de+1.pem',
@@ -164,13 +163,13 @@ module.exports = {
164
163
  beforeCompile(compiler, callback) {
165
164
  let path = Path.join(process.cwd(), 'public/sprite'),
166
165
  filename = 'sprite.svg',
167
- exists = fs.existsSync(path);
166
+ exists = Fs.existsSync(path);
168
167
 
169
168
  if (!exists) {
170
- fs.mkdirSync(path, {
169
+ Fs.mkdirSync(path, {
171
170
  recursive: true,
172
171
  });
173
- fs.appendFile(Path.join(path, filename), '#', (err) => {
172
+ Fs.appendFile(Path.join(path, filename), '#', (err) => {
174
173
  if (err) {
175
174
  throw err;
176
175
  }
@@ -5,7 +5,6 @@ const webpack = require('webpack'),
5
5
  Glob = require('glob'),
6
6
  Path = require('path'),
7
7
  privatePath = process.env.PLUGIN_PATH,
8
- isModern = process.env.MODE === 'modern',
9
8
  config = {
10
9
  devtool: 'nosources-source-map',
11
10
  performance: {
@@ -15,11 +14,8 @@ const webpack = require('webpack'),
15
14
  },
16
15
  mode: 'production',
17
16
  optimization: {
18
- concatenateModules: true,
19
- removeAvailableModules: true,
20
- removeEmptyChunks: true,
21
- sideEffects: false,
22
- minimize: true,
17
+ splitChunks: false,
18
+ runtimeChunk: false,
23
19
  minimizer: [
24
20
  new CssMinimizerPlugin({
25
21
  minimizerOptions: {
@@ -36,21 +32,13 @@ const webpack = require('webpack'),
36
32
  ]
37
33
  }),
38
34
  new TerserPlugin({
35
+ minify: TerserPlugin.swcMinify,
39
36
  terserOptions: {
40
37
  compress: {
41
38
  drop_console: true,
42
39
  },
43
- mangle: true,
44
- ecma: isModern ? 8 : 5,
45
- keep_classnames: false,
46
- keep_fnames: false,
47
- ie8: false,
48
- module: false,
49
- nameCache: null, // or specify a name cache object
50
- safari10: !isModern,
51
- toplevel: false,
52
- warnings: false,
53
40
  },
41
+ parallel: true,
54
42
  extractComments: false,
55
43
  }),
56
44
  ],
@@ -3,15 +3,14 @@ const Path = require('path'),
3
3
  MiniCssExtractPlugin = require('mini-css-extract-plugin'),
4
4
  privatePath = process.env.PLUGIN_PATH,
5
5
  vendorPath = process.env.VENDOR_PATH,
6
- spritePath = process.env.SPRITE_PATH ?? 'custom/plugins/PxswTheme/src/Resources/views/storefront',
6
+ spritePath = process.env.SPRITE_PATH ?? 'custom/static-plugins/PxswTheme/src/Resources/views/storefront',
7
7
  swNodePath = process.env.SW_NODE_PATH ?? './vendor/shopware/storefront/Resources/app/storefront/vendor',
8
8
  swAliasPath = process.env.SW_ALIAS_PATH ?? '/vendor/shopware/storefront/Resources/app/storefront/src',
9
+ isProd = process.env.NODE_ENV === 'production',
9
10
  ChangeCase = require('change-case'),
10
11
  Consola = require('consola'),
11
12
  TwigAssetEmitterPlugin = require('@pixolith/webpack-twig-assets-emitter-plugin'),
12
- entry = require('webpack-glob-entry'),
13
- isProd = process.env.NODE_ENV === 'production',
14
- isModern = process.env.MODE === 'modern',
13
+ Entry = require('webpack-glob-entry'),
15
14
  SvgStorePlugin = require('@pixolith/external-svg-sprite-loader'),
16
15
  publicPath = process.env.PUBLIC_PATH,
17
16
  ASSET_URL = process.env.ASSET_URL || '/',
@@ -19,27 +18,29 @@ const Path = require('path'),
19
18
  outputConfig = {
20
19
  path: Path.join(process.cwd(), publicPath),
21
20
  publicPath: ASSET_URL,
22
- chunkFilename: `js/[name]${
23
- isModern ? '.modern' : '' + isProd ? '.[contenthash]' : ''
24
- }.js`,
21
+ chunkFilename: (chunkData) => {
22
+ return `js/chunk[name]${
23
+ isProd ? '.[contenthash:6]' : ''
24
+ }.js`;
25
+ },
25
26
  filename: (chunkData) => {
26
- return `js/${chunkData.chunk.name.toLowerCase()}${(isModern
27
- ? '.modern'
28
- : '') + (isProd ? `.${chunkData.chunk.hash}` : '')}.js`;
27
+ return `js/${chunkData.chunk.name.toLowerCase()}${
28
+ isProd ? `.[contenthash:6]` : ''
29
+ }.js`;
29
30
  },
30
31
  },
31
32
  miniCssChunksConfig = {
32
- filename: `css/[name]${isModern ? '.modern' : ''}${
33
+ filename: `css/[name]${
33
34
  isProd ? '.[contenthash]' : ''
34
35
  }.css`,
35
- chunkFilename: `css/[name].vendor${isModern ? '.modern' : ''}${
36
+ chunkFilename: `css/[name].vendor${
36
37
  isProd ? '.[contenthash]' : ''
37
38
  }.css`
38
39
  };
39
40
 
40
41
  module.exports = {
41
42
  entry: () => {
42
- let entriesPlugins = entry(
43
+ let entriesPlugins = Entry(
43
44
  (filePath) =>
44
45
  ChangeCase.paramCase(
45
46
  filePath.match(/plugins\/(Pxsw[\w]*)\//)[1],
@@ -47,7 +48,7 @@ module.exports = {
47
48
  Path.resolve(privatePath, 'index.js'),
48
49
  );
49
50
 
50
- let entriesVendor = entry(
51
+ let entriesVendor = Entry(
51
52
  (filePath) =>
52
53
  ChangeCase.paramCase(
53
54
  filePath.match(/(vendor\/pxsw\/[\w-]*)\//)[1],
@@ -81,32 +82,30 @@ module.exports = {
81
82
  {
82
83
  test: /\.js$/,
83
84
  exclude: (file) => {
84
- if (
85
- !isModern &&
86
- /node_modules/.test(file) &&
87
- JSON.parse(process.env.JS_TRANSPILE) &&
88
- JSON.parse(process.env.JS_TRANSPILE).length &&
89
- JSON.parse(process.env.JS_TRANSPILE).filter((lib) => {
90
- return new RegExp(lib).test(file);
91
- }).length > 0
92
- ) {
93
- return false;
94
- }
95
-
96
- if (/node_modules/.test(file)) {
97
- return true;
98
- }
99
-
100
- return false;
85
+ return /node_modules/.test(file);
101
86
  },
102
87
  use: [
103
88
  {
104
- loader: 'babel-loader',
89
+ loader: 'swc-loader',
105
90
  options: {
106
- configFile: Path.resolve(
107
- __dirname,
108
- 'babel.config.js',
109
- ),
91
+ env: {
92
+ mode: 'entry',
93
+ coreJs: '3.34.0',
94
+ // .browserlist settings are not found by swc-loader, so we load it manually: https://github.com/swc-project/swc/issues/3365
95
+ targets: require('browserslist').loadConfig({
96
+ config: './package.json',
97
+ }),
98
+ },
99
+ jsc: {
100
+ parser: {
101
+ syntax: 'typescript',
102
+ },
103
+ transform: {
104
+ // NEXT-30535 - Restore babel option to not use defineProperty for class fields.
105
+ // Previously (in v6.5.x) this was done by `@babel/preset-typescript` automatically.
106
+ useDefineForClassFields: false,
107
+ },
108
+ },
110
109
  },
111
110
  },
112
111
  ],
@@ -215,28 +214,22 @@ module.exports = {
215
214
  }),
216
215
  new TwigAssetEmitterPlugin({
217
216
  includes: ['js', 'css'],
218
- ignoreFiles: [/.*icons.*\.js/],
217
+ ignoreFiles: [/.*icons.*\.js/, /.*chunk.*\.js/],
219
218
  template: {
220
- [isModern ? 'scriptsmodern' : 'scripts']: {
219
+ 'scripts': {
221
220
  namespace: '@Storefront/storefront',
222
221
  path: '',
223
- filename: isModern
224
- ? '_px_base_modern.html.twig'
225
- : '_px_base.html.twig',
222
+ filename: '_px_base.html.twig',
226
223
  },
227
- [isModern ? 'stylesmodern' : 'styles']: {
224
+ 'styles': {
228
225
  namespace: '@Storefront/storefront',
229
226
  path: 'layout',
230
- filename: isModern
231
- ? '_px_meta_modern.html.twig'
232
- : '_px_meta.html.twig',
227
+ filename: '_px_meta.html.twig',
233
228
  },
234
- [isModern ? 'hintsmodern' : 'hints']: {
229
+ 'hints': {
235
230
  namespace: '@Storefront/storefront',
236
231
  path: 'layout',
237
- filename: isModern
238
- ? '_px_meta_modern.html.twig'
239
- : '_px_meta.html.twig',
232
+ filename: '_px_meta.html.twig',
240
233
  },
241
234
  },
242
235
  }),