@pixolith/webpack-sw6-config 11.0.9 → 12.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.
@@ -13,188 +13,183 @@ const webpack = require('webpack'),
13
13
  Sass = require('sass'),
14
14
  TimeFixPlugin = require('time-fix-plugin');
15
15
 
16
- module.exports = {
17
- target: 'web',
18
- mode: 'development',
19
- resolve: {
20
- modules: [
21
- 'node_modules',
22
- Path.resolve(config.shopwareVendorPath),
23
- ],
24
- alias: {
25
- src: Path.resolve(config.shopwarePluginPath),
26
- vendor: Path.resolve(config.shopwareVendorPath),
16
+ module.exports = function createDevConfig(themeOptions) {
17
+ let resourcesPaths =
18
+ themeOptions && themeOptions.resourcesPaths
19
+ ? themeOptions.resourcesPaths
20
+ : JSON.parse(process.env.RESOURCES_PATHS || '[]');
21
+
22
+ let resolvedResources = resourcesPaths.filter((path) => {
23
+ return Glob.sync(path).length > 0;
24
+ });
25
+
26
+ return {
27
+ target: 'web',
28
+ mode: 'development',
29
+ resolve: {
30
+ modules: ['node_modules', Path.resolve(config.shopwareVendorPath)],
31
+ alias: {
32
+ src: Path.resolve(config.shopwarePluginPath),
33
+ vendor: Path.resolve(config.shopwareVendorPath),
34
+ },
27
35
  },
28
- },
29
- devtool: 'inline-cheap-module-source-map',
30
- module: {
31
- rules: [
32
- {
33
- test: /(\.scss|\.css)$/,
34
- use: [
35
- config.isProd ? MiniCssExtractPlugin.loader : 'style-loader',
36
- {
37
- loader: 'css-loader',
38
- options: {
39
- importLoaders: 1,
40
- sourceMap: !config.isProd,
36
+ devtool: 'inline-cheap-module-source-map',
37
+ module: {
38
+ rules: [
39
+ {
40
+ test: /(\.scss|\.css)$/,
41
+ use: [
42
+ config.isProd
43
+ ? MiniCssExtractPlugin.loader
44
+ : 'style-loader',
45
+ {
46
+ loader: 'css-loader',
47
+ options: {
48
+ importLoaders: 1,
49
+ sourceMap: !config.isProd,
50
+ },
41
51
  },
42
- },
43
- config.isProd && config.mediaQueries ? MediaQueryPlugin.loader : '',
44
- {
45
- loader: 'postcss-loader',
46
- options: {
47
- sourceMap: !config.isProd,
48
- postcssOptions: {
49
- config: Path.resolve(__dirname, 'postcss.config.js'),
52
+ config.isProd && config.mediaQueries
53
+ ? MediaQueryPlugin.loader
54
+ : '',
55
+ {
56
+ loader: 'postcss-loader',
57
+ options: {
58
+ sourceMap: !config.isProd,
59
+ postcssOptions: {
60
+ config: Path.resolve(
61
+ __dirname,
62
+ 'postcss.config.js',
63
+ ),
64
+ },
50
65
  },
51
66
  },
52
- },
53
- {
54
- loader: 'sass-loader',
55
- options: {
56
- sourceMap: !config.isProd,
57
- additionalData: `$asset_url: '${config.assetUrl}';`,
58
- sassOptions: {
59
- quietDeps: true,
60
- logger: Sass.Logger.silent,
67
+ {
68
+ loader: 'sass-loader',
69
+ options: {
70
+ sourceMap: !config.isProd,
71
+ additionalData: `$asset_url: '${config.assetUrl}';`,
72
+ sassOptions: {
73
+ quietDeps: true,
74
+ logger: Sass.Logger.silent,
75
+ },
61
76
  },
62
77
  },
63
- },
64
- {
65
- loader: 'sass-resources-loader',
66
- options: {
67
- resources: JSON.parse(
68
- process.env.RESOURCES_PATHS,
69
- ).filter((path) => {
70
- return Glob.sync(path).length > 0;
71
- }),
72
- hoistUseStatements: true
78
+ {
79
+ loader: 'sass-resources-loader',
80
+ options: {
81
+ resources: resolvedResources,
82
+ hoistUseStatements: true,
83
+ },
73
84
  },
74
- },
75
- ],
76
- },
77
- {
78
- test: /\.(html|twig)$/,
79
- use: [
80
- {
81
- loader: 'html-loader',
82
- },
83
- ],
85
+ ],
86
+ },
87
+ {
88
+ test: /\.(html|twig)$/,
89
+ use: [
90
+ {
91
+ loader: 'html-loader',
92
+ },
93
+ ],
94
+ },
95
+ ],
96
+ },
97
+ stats: 'errors-warnings',
98
+ devServer: {
99
+ allowedHosts: 'all',
100
+ client: {
101
+ webSocketURL: {
102
+ hostname: 'node.px-staging.de',
103
+ protocol: 'wss',
104
+ port:
105
+ process.env.SHOPWARE_MODE === 'administration'
106
+ ? 8080
107
+ : 8081,
108
+ },
109
+ overlay: {
110
+ warnings: false,
111
+ errors: true,
112
+ },
84
113
  },
85
- ],
86
- },
87
- stats: 'errors-warnings',
88
- devServer: {
89
- allowedHosts: 'all',
90
- client: {
91
- webSocketURL: {
92
- hostname: 'node.px-staging.de',
93
- protocol: 'wss',
94
- port: process.env.SHOPWARE_MODE === 'administration' ? 8080 : 8081,
114
+ headers: {
115
+ 'Access-Control-Allow-Origin': '*',
116
+ 'Access-Control-Allow-Methods':
117
+ 'GET, POST, PUT, DELETE, PATCH, OPTIONS',
118
+ 'Access-Control-Allow-Headers':
119
+ 'X-Requested-With, content-type, Authorization',
95
120
  },
96
- overlay: {
97
- warnings: false,
98
- errors: true,
121
+ port: process.env.SHOPWARE_MODE === 'administration' ? 8080 : 8081,
122
+ server: !config.isProd
123
+ ? {
124
+ type: 'https',
125
+ options: {
126
+ ca: Fs.readFileSync(
127
+ Path.join(
128
+ process.cwd() +
129
+ '/.ddev/ssl/_wildcard.px-staging.de+1-client.pem',
130
+ ),
131
+ ),
132
+ key: Fs.readFileSync(
133
+ Path.join(
134
+ process.cwd() +
135
+ '/.ddev/ssl/_wildcard.px-staging.de+1-key.pem',
136
+ ),
137
+ ),
138
+ cert: Fs.readFileSync(
139
+ Path.join(
140
+ process.cwd() +
141
+ '/.ddev/ssl/_wildcard.px-staging.de+1.pem',
142
+ ),
143
+ ),
144
+ },
145
+ }
146
+ : 'http',
147
+ devMiddleware: {
148
+ writeToDisk: true,
99
149
  },
100
- },
101
- headers: {
102
- 'Access-Control-Allow-Origin': '*',
103
- 'Access-Control-Allow-Methods':
104
- 'GET, POST, PUT, DELETE, PATCH, OPTIONS',
105
- 'Access-Control-Allow-Headers':
106
- 'X-Requested-With, content-type, Authorization',
107
- },
108
- port: process.env.SHOPWARE_MODE === 'administration' ? 8080 : 8081,
109
- server: !config.isProd
110
- ? {
111
- type: 'https',
112
- options: {
113
- ca: Fs.readFileSync(
114
- Path.join(
115
- process.cwd() +
116
- '/.ddev/ssl/_wildcard.px-staging.de+1-client.pem',
117
- ),
118
- ),
119
- key: Fs.readFileSync(
120
- Path.join(
121
- process.cwd() +
122
- '/.ddev/ssl/_wildcard.px-staging.de+1-key.pem',
123
- ),
124
- ),
125
- cert: Fs.readFileSync(
126
- Path.join(
127
- process.cwd() +
128
- '/.ddev/ssl/_wildcard.px-staging.de+1.pem',
129
- ),
130
- ),
150
+ setupMiddlewares: (middlewares, devServer) => {
151
+ if (!devServer) {
152
+ throw new Error('webpack-dev-server is not defined');
131
153
  }
132
- }
133
- : 'http',
134
- devMiddleware: {
135
- writeToDisk: true,
136
- },
137
- setupMiddlewares: (middlewares, devServer) => {
138
- if (!devServer) {
139
- throw new Error("webpack-dev-server is not defined")
140
- }
141
-
142
- Consola.success(
143
- `Starting webpack in [${process.env.NODE_ENV}] with [${process.env.SHOPWARE_MODE}]`,
144
- );
145
-
146
- watcher.watch(config);
147
154
 
148
- return middlewares;
149
- },
150
- },
151
- plugins: [
152
- new ESLintPlugin({
153
- exclude: [
154
- '**/node_modules/**',
155
- 'vendor'
156
- ]
157
- }),
158
- new HookPlugin({
159
- beforeCompile(compiler, callback) {
160
- let path = Path.join(config.outputPath, 'sprite'),
161
- filename = 'sprite.svg',
162
- exists = Fs.existsSync(path);
155
+ Consola.success(
156
+ `Starting webpack in [${process.env.NODE_ENV}] with [${process.env.SHOPWARE_MODE}]`,
157
+ );
163
158
 
164
- if (!exists) {
165
- Fs.mkdirSync(path, {
166
- recursive: true,
167
- });
168
- Fs.appendFile(Path.join(path, filename), '#', (err) => {
169
- if (err) {
170
- throw err;
171
- }
172
- });
173
- }
159
+ watcher.watch(config);
174
160
 
175
- callback();
161
+ return middlewares;
176
162
  },
177
- failed() {
178
- watcher.run(null, config);
179
- },
180
- }),
163
+ },
164
+ plugins: [
165
+ new ESLintPlugin({
166
+ exclude: ['**/node_modules/**', 'vendor'],
167
+ }),
168
+ new HookPlugin({
169
+ failed() {
170
+ watcher.onFileChange(null, config);
171
+ },
172
+ }),
181
173
 
182
- new TimeFixPlugin(),
174
+ new TimeFixPlugin(),
183
175
 
184
- new webpack.DefinePlugin({
185
- 'process.env.NODE_ENV': JSON.stringify(
186
- process.env.NODE_ENV || 'development',
187
- ),
188
- 'process.env.ASSET_URL': JSON.stringify(config.assetUrl),
189
- 'process.env.RESOURCES_PATHS': JSON.stringify(process.env.RESOURCES_PATHS || '[]'),
190
- }),
191
- ].concat(
192
- config.isProd && config.mediaQueries
193
- ? new MediaQueryPlugin({
194
- include: true,
195
- queries: JSON.parse(config.mediaQueries)
196
- })
197
- : []
198
- ),
199
- watch: false,
176
+ new webpack.DefinePlugin({
177
+ 'process.env.NODE_ENV': JSON.stringify(
178
+ process.env.NODE_ENV || 'development',
179
+ ),
180
+ 'process.env.ASSET_URL': JSON.stringify(config.assetUrl),
181
+ 'process.env.RESOURCES_PATHS': JSON.stringify(
182
+ JSON.stringify(resourcesPaths),
183
+ ),
184
+ }),
185
+ ].concat(
186
+ config.isProd && config.mediaQueries
187
+ ? new MediaQueryPlugin({
188
+ include: true,
189
+ queries: JSON.parse(config.mediaQueries),
190
+ })
191
+ : [],
192
+ ),
193
+ watch: false,
194
+ };
200
195
  };