@atomicsmash/compiler 0.7.3 → 0.7.5

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/dist/index.js +99 -53
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -65,15 +65,16 @@ const tailwindPostCSSPlugin = await import("@tailwindcss/postcss")
65
65
  // Add optional support for Vue if vue-loader is installed
66
66
  const vueConfig = await import("vue-loader")
67
67
  .then((vueLoaderModule) => ({
68
- loader: [
69
- {
70
- test: /\.vue$/,
71
- loader: "vue-loader",
72
- },
73
- ],
68
+ loader: [{ test: /\.vue$/, loader: "vue-loader" }],
74
69
  plugin: [new vueLoaderModule.VueLoaderPlugin()],
70
+ globals: {
71
+ __VUE_OPTIONS_API__: "true",
72
+ __VUE_PROD_DEVTOOLS__: "false",
73
+ __VUE_PROD_HYDRATION_MISMATCH_DETAILS__: "false",
74
+ },
75
+ aliases: { vue: "vue/dist/vue.esm-bundler.js" },
75
76
  }))
76
- .catch(() => ({ loader: [], plugin: [] }));
77
+ .catch(() => ({ loader: [], plugin: [], globals: {}, aliases: {} }));
77
78
  const postCSSConfig = [
78
79
  [
79
80
  // Support tailwind if package is found
@@ -89,6 +90,30 @@ const postCSSConfig = [
89
90
  ],
90
91
  ...(MODE === "production" ? [cssNano] : []),
91
92
  ];
93
+ function getEsBuildLoaderSetup(loader) {
94
+ return {
95
+ use: {
96
+ loader: "esbuild-loader",
97
+ options: {
98
+ loader: loader,
99
+ // Set target to match the browserslist config
100
+ target: browserslistToEsbuild(),
101
+ tsconfig: process.cwd() + "/tsconfig.json",
102
+ },
103
+ },
104
+ exclude: (file) => {
105
+ // Exclude all block.json.ts files (handled by a separate loader).
106
+ if (argv.experimentalBlocksSupport && file.includes("block.json")) {
107
+ return true;
108
+ }
109
+ // Exclude node_modules files from transpilation unless they are vue files and the vue-loader is present
110
+ if (vueConfig.loader.length > 0) {
111
+ return file.includes("node_modules") && !file.includes(".vue.js");
112
+ }
113
+ return file.includes("node_modules");
114
+ },
115
+ };
116
+ }
92
117
  const compiler = webpack({
93
118
  resolveLoader: {
94
119
  modules: [
@@ -143,14 +168,13 @@ const compiler = webpack({
143
168
  path: distFolder,
144
169
  },
145
170
  resolve: {
171
+ alias: { ...vueConfig.aliases },
146
172
  // support TSConfig paths as aliases
147
173
  plugins: [
148
- new TsconfigPathsPlugin({
149
- configFile: process.cwd() + "/tsconfig.json",
150
- }),
174
+ new TsconfigPathsPlugin({ configFile: process.cwd() + "/tsconfig.json" }),
151
175
  ],
152
176
  // resolve TS extensions
153
- extensions: [".tsx", ".ts", ".js", ".jsx"],
177
+ extensions: [".tsx", ".ts", ".js", ".jsx", ".vue"],
154
178
  },
155
179
  module: {
156
180
  rules: [
@@ -159,25 +183,14 @@ const compiler = webpack({
159
183
  // Use ESBuild loader to transpile JS & TS files
160
184
  {
161
185
  test: /\.[jt]sx?$/,
162
- use: {
163
- loader: "esbuild-loader",
164
- options: {
165
- // Set target to match the browserslist config
166
- target: browserslistToEsbuild(),
167
- tsconfig: process.cwd() + "/tsconfig.json",
168
- },
169
- },
170
- exclude: (file) => {
171
- // Exclude all block.json.ts files (handled by a separate loader).
172
- if (argv.experimentalBlocksSupport && file.includes("block.json")) {
173
- return true;
174
- }
175
- // Exclude node_modules files from transpilation unless they are vue files and the vue-loader is present
176
- if (vueConfig.loader.length > 0) {
177
- return file.includes("node_modules") && !file.includes(".vue.js");
178
- }
179
- return file.includes("node_modules");
180
- },
186
+ resourceQuery: (value) => value.includes("vue"),
187
+ // Vue files require explicitly informing ESBuild of the type of loader to use.
188
+ ...getEsBuildLoaderSetup("ts"),
189
+ },
190
+ {
191
+ test: /\.[jt]sx?$/,
192
+ resourceQuery: (value) => !value.includes("vue"),
193
+ ...getEsBuildLoaderSetup("default"),
181
194
  },
182
195
  ...(argv.experimentalBlocksSupport
183
196
  ? [
@@ -196,13 +209,34 @@ const compiler = webpack({
196
209
  // Transpile SCSS files and run the result through postcss
197
210
  {
198
211
  test: /\.s[ac]ss$/i,
199
- exclude: /node_modules/,
200
212
  type: "asset/resource",
201
213
  generator: {
202
214
  binary: false,
203
- filename: (pathData) => relative(srcFolder, pathData.filename ?? "")
204
- .replace(".scss", ".[contenthash].css")
205
- .replace("styles/", "css/"),
215
+ filename: (pathData) => {
216
+ const fileName = pathData.filename;
217
+ if (!fileName) {
218
+ return;
219
+ }
220
+ const isVendorFile = fileName.includes("node_modules");
221
+ if (isVendorFile) {
222
+ const vendorPathData = fileName.split(pathSeparator);
223
+ const nodeModulesPosition = vendorPathData.findIndex((value) => value.includes("node_modules"));
224
+ const vendorArray = vendorPathData.slice(nodeModulesPosition + 1, nodeModulesPosition + 3);
225
+ let vendor;
226
+ if (vendorArray[0]?.startsWith("@")) {
227
+ vendor = vendorArray.join(pathSeparator);
228
+ }
229
+ else {
230
+ vendor = vendorArray[0] ?? "";
231
+ }
232
+ return ["css", "vendor", vendor, vendorPathData.at(-1)]
233
+ .join(pathSeparator)
234
+ .replace(".scss", ".[contenthash].css");
235
+ }
236
+ return relative(srcFolder, pathData.filename ?? "")
237
+ .replace(".scss", ".[contenthash].css")
238
+ .replace("styles/", "css/");
239
+ },
206
240
  },
207
241
  use: [
208
242
  {
@@ -216,22 +250,41 @@ const compiler = webpack({
216
250
  },
217
251
  {
218
252
  loader: "sass-loader",
219
- options: {
220
- sourceMap: MODE === "development",
221
- },
253
+ options: { sourceMap: MODE === "development" },
222
254
  },
223
255
  ],
224
256
  },
225
257
  // Run the css files through postcss
226
258
  {
227
259
  test: /\.css$/i,
228
- exclude: /node_modules/,
229
260
  type: "asset/resource",
230
261
  generator: {
231
262
  binary: false,
232
- filename: (pathData) => relative(srcFolder, pathData.filename ?? "")
233
- .replace(".css", ".[contenthash].css")
234
- .replace("styles/", "css/"),
263
+ filename: (pathData) => {
264
+ const fileName = pathData.filename;
265
+ if (!fileName) {
266
+ return;
267
+ }
268
+ const isVendorFile = fileName.includes("node_modules");
269
+ if (isVendorFile) {
270
+ const vendorPathData = fileName.split(pathSeparator);
271
+ const nodeModulesPosition = vendorPathData.findIndex((value) => value.includes("node_modules"));
272
+ const vendorArray = vendorPathData.slice(nodeModulesPosition + 1, nodeModulesPosition + 3);
273
+ let vendor;
274
+ if (vendorArray[0]?.startsWith("@")) {
275
+ vendor = vendorArray.join(pathSeparator);
276
+ }
277
+ else {
278
+ vendor = vendorArray[0] ?? "";
279
+ }
280
+ return ["css", "vendor", vendor, vendorPathData.at(-1)]
281
+ .join(pathSeparator)
282
+ .replace(".css", ".[contenthash].css");
283
+ }
284
+ return relative(srcFolder, pathData.filename ?? "")
285
+ .replace(".css", ".[contenthash].css")
286
+ .replace("styles/", "css/");
287
+ },
235
288
  },
236
289
  use: [
237
290
  {
@@ -260,6 +313,7 @@ const compiler = webpack({
260
313
  }
261
314
  if (entry.key === "assets.php" ||
262
315
  entry.key === "wordpress-assets-info.php" ||
316
+ entry.key.endsWith(".map") ||
263
317
  entry.key.startsWith("fonts") ||
264
318
  entry.key.startsWith("images")) {
265
319
  return false;
@@ -281,15 +335,8 @@ const compiler = webpack({
281
335
  }),
282
336
  // Create an SVG sprite from a folder of provided icons
283
337
  new SVGSpritemapPlugin(`${srcFolder}/icons/*.svg`, {
284
- output: {
285
- filename: "icons/sprite.[contenthash].svg",
286
- },
287
- sprite: {
288
- prefix: "",
289
- generate: {
290
- title: false,
291
- },
292
- },
338
+ output: { filename: "icons/sprite.[contenthash].svg" },
339
+ sprite: { prefix: "", generate: { title: false } },
293
340
  }),
294
341
  // Copy fonts and images from the src folder to assets (available for backwards compatibility, not recommended)
295
342
  new CopyPlugin({
@@ -331,13 +378,12 @@ const compiler = webpack({
331
378
  // Support Vue files if vue-loader is present
332
379
  ...vueConfig.plugin,
333
380
  ...(argv.experimentalBlocksSupport ? [new BlocksPlugin(srcFolder)] : []),
381
+ new webpack.DefinePlugin({ ...vueConfig.globals }),
334
382
  ],
335
383
  optimization: {
336
384
  minimizer: [
337
385
  // Minify JS files
338
- new EsbuildPlugin({
339
- target: browserslistToEsbuild(),
340
- }),
386
+ new EsbuildPlugin({ target: browserslistToEsbuild() }),
341
387
  ],
342
388
  },
343
389
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@atomicsmash/compiler",
3
3
  "type": "module",
4
- "version": "0.7.3",
4
+ "version": "0.7.5",
5
5
  "description": "A universal compiler for all Atomic Smash projects.",
6
6
  "keywords": [
7
7
  "cli",