@atomicsmash/compiler 0.4.1 → 0.5.1

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.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAsBA,OAAO,CAAC,MAAM,CAAC;IAEd,UAAU,MAAM,CAAC;QAEhB,UAAU,UAAU;YACnB,QAAQ,EAAE,YAAY,GAAG,aAAa,GAAG,MAAM,GAAG,SAAS,CAAC;SAC5D;KACD;CACD"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAuBA,OAAO,CAAC,MAAM,CAAC;IAEd,UAAU,MAAM,CAAC;QAEhB,UAAU,UAAU;YACnB,QAAQ,EAAE,YAAY,GAAG,aAAa,GAAG,MAAM,GAAG,SAAS,CAAC;SAC5D;KACD;CACD"}
package/dist/index.js CHANGED
@@ -1,11 +1,11 @@
1
1
  #!/usr/bin/env node
2
- import { sep as pathSeparator, extname, resolve as resolvePath, } from "node:path";
2
+ import { sep as pathSeparator, extname, resolve as resolvePath, relative, } from "node:path";
3
3
  import DependencyExtractionWebpackPlugin from "@wordpress/dependency-extraction-webpack-plugin";
4
+ import browserslistToEsbuild from "browserslist-to-esbuild";
4
5
  import CopyPlugin from "copy-webpack-plugin";
5
6
  import cssNano from "cssnano";
7
+ import { EsbuildPlugin } from "esbuild-loader";
6
8
  import glob from "fast-glob";
7
- import postCSSIncreaseSpecificity from "postcss-increase-specificity";
8
- import postCSSContext from "postcss-plugin-context";
9
9
  import postCSSPresetEnv from "postcss-preset-env";
10
10
  import SVGSpritemapPlugin from "svg-spritemap-webpack-plugin";
11
11
  import { TsconfigPathsPlugin } from "tsconfig-paths-webpack-plugin";
@@ -64,34 +64,38 @@ const vueConfig = await import("vue-loader")
64
64
  .catch(() => ({ loader: [], plugin: [] }));
65
65
  const postCSSConfig = [
66
66
  [
67
+ // Support tailwind if package is found
67
68
  ...tailwindPostCSSPlugin,
68
69
  postCSSPresetEnv({
70
+ // Support all CSS that is considered stable.
69
71
  stage: 2,
70
72
  features: {
73
+ // Polyfill support for custom media queries
71
74
  "custom-media-queries": true,
72
75
  },
73
76
  }),
74
- postCSSContext({
75
- wordpressEditor: postCSSIncreaseSpecificity({
76
- repeat: 1,
77
- stackableRoot: ".is-root-container",
78
- }),
79
- }),
80
77
  ],
81
78
  ...(MODE === "production" ? [cssNano] : []),
82
79
  ];
83
80
  const compiler = webpack({
84
81
  resolveLoader: {
85
82
  modules: [
83
+ // Get modules from project node_modules folder
86
84
  "node_modules",
85
+ // Get modules from this package's internal node modules folder once installed
87
86
  resolvePath(import.meta.dirname, "../", "node_modules"),
88
87
  ],
89
88
  },
89
+ // Add sourcemaps in dev mode
90
90
  devtool: MODE === "development" ? "source-map" : false,
91
+ // Set the environment mode from NODE_ENV.
91
92
  mode: MODE,
92
93
  entry: await glob([
94
+ // Parse all direct children of the JS folder, as long as they are JS & TS files
93
95
  `${srcFolder}/js/*.{js,ts,jsx,tsx}`,
96
+ // Parse all direct children of the CSS folder, as long as they are CSS files
94
97
  `${srcFolder}/css/*.css`,
98
+ // Parse all nested children of the CSS folder, as long as they are non-partial SCSS files
95
99
  `${srcFolder}/css/**/[^_]*.s[ac]ss`,
96
100
  ]).then((paths) => {
97
101
  const entryPoints = {};
@@ -99,43 +103,45 @@ const compiler = webpack({
99
103
  const entryName = path.replace(srcFolder, "").replace(extname(path), "");
100
104
  entryPoints[entryName] = {
101
105
  import: path,
106
+ // Output filenames with content hash for fingerprinting
102
107
  filename: `${path.replace(`${srcFolder}${pathSeparator}`, "").replace(extname(path), "")}${MODE === "production" ? `.[contenthash]` : ""}.js`,
103
108
  };
104
109
  });
105
110
  return entryPoints;
106
111
  }),
107
112
  output: {
113
+ // Output filenames with content hash for fingerprinting
108
114
  filename: "js/[name].[contenthash].js",
115
+ // Clear files between runs
109
116
  clean: true,
110
117
  library: {
118
+ // Output JS files with Universal Module Definition
111
119
  type: "umd",
112
120
  },
121
+ // Set the output folder
113
122
  path: distFolder,
114
123
  },
115
124
  resolve: {
125
+ // support TSConfig paths as aliases
116
126
  plugins: [new TsconfigPathsPlugin()],
127
+ // resolve TS extensions
117
128
  extensions: [".tsx", ".ts", ".js", ".jsx"],
118
129
  },
119
130
  module: {
120
131
  rules: [
132
+ // Support Vue files if vue-loader is present
121
133
  ...vueConfig.loader,
134
+ // Use ESBuild loader to transpile JS & TS files
122
135
  {
123
136
  test: /\.[jt]sx?$/,
124
137
  use: {
125
- loader: "babel-loader",
138
+ loader: "esbuild-loader",
126
139
  options: {
127
- presets: [
128
- "@babel/preset-typescript",
129
- [
130
- "@babel/preset-react",
131
- {
132
- runtime: "automatic",
133
- },
134
- ],
135
- "@babel/preset-env",
136
- ],
140
+ // Set target to match the browserslist config
141
+ target: browserslistToEsbuild(),
137
142
  },
138
143
  },
144
+ // Exclude node_modules files from transpilation unless they are vue files and the vue-loader is present
139
145
  exclude: (file) => {
140
146
  if (vueConfig.loader.length > 0) {
141
147
  return file.includes("node_modules") && !file.includes(".vue.js");
@@ -143,6 +149,7 @@ const compiler = webpack({
143
149
  return file.includes("node_modules");
144
150
  },
145
151
  },
152
+ // Transpile SCSS files and run the result through postcss
146
153
  {
147
154
  test: /\.s[ac]ss$/i,
148
155
  exclude: /node_modules/,
@@ -169,6 +176,7 @@ const compiler = webpack({
169
176
  },
170
177
  ],
171
178
  },
179
+ // Run the css files through postcss
172
180
  {
173
181
  test: /\.css$/i,
174
182
  exclude: /node_modules/,
@@ -192,7 +200,9 @@ const compiler = webpack({
192
200
  ],
193
201
  },
194
202
  plugins: [
203
+ // Output progress information when compiling
195
204
  new webpack.ProgressPlugin(),
205
+ // Generate a manifest file of assets to make it possible to target fingerprinted files
196
206
  new WebpackAssetsManifest({
197
207
  writeToDisk: true,
198
208
  output: `${distFolder}/assets-manifest.json`,
@@ -211,6 +221,7 @@ const compiler = webpack({
211
221
  return entry;
212
222
  },
213
223
  }),
224
+ // Create an SVG sprite from a folder of provided icons
214
225
  new SVGSpritemapPlugin(`${srcFolder}/icons/*.svg`, {
215
226
  output: {
216
227
  filename: "icons/sprite.[contenthash].svg",
@@ -222,26 +233,44 @@ const compiler = webpack({
222
233
  },
223
234
  },
224
235
  }),
236
+ // Copy fonts and images from the src folder to assets (available for backwards compatibility, not recommended)
225
237
  new CopyPlugin({
226
238
  patterns: [
227
239
  {
228
- from: `${srcFolder}/fonts`,
229
- to: "[path]fonts/[name][ext]",
240
+ from: "**/*",
241
+ context: resolvePath(srcFolder, "fonts"),
242
+ to({ context, absoluteFilename }) {
243
+ return `fonts/${relative(context, absoluteFilename ?? "")}`;
244
+ },
230
245
  noErrorOnMissing: true,
231
246
  },
232
247
  {
233
- from: `${srcFolder}/images`,
234
- to: "[path]images/[name][ext]",
248
+ from: "**/*",
249
+ context: resolvePath(srcFolder, "images"),
250
+ to({ context, absoluteFilename }) {
251
+ return `images/${relative(context, absoluteFilename ?? "")}`;
252
+ },
235
253
  noErrorOnMissing: true,
236
254
  },
237
255
  ],
238
256
  }),
257
+ // Output a bundle analysis if flag was provided
239
258
  ...(argv.analyse ? [new BundleAnalyzerPlugin({})] : []),
259
+ // Extract wordpress dependencies from js files and output a wordpress assets file for enqueues
240
260
  new DependencyExtractionWebpackPlugin({
241
261
  combineAssets: true,
242
262
  }),
263
+ // Support Vue files if vue-loader is present
243
264
  ...vueConfig.plugin,
244
265
  ],
266
+ optimization: {
267
+ minimizer: [
268
+ // Minify JS files
269
+ new EsbuildPlugin({
270
+ target: browserslistToEsbuild(),
271
+ }),
272
+ ],
273
+ },
245
274
  });
246
275
  if (argv.watch) {
247
276
  const watching = compiler.watch({
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@atomicsmash/compiler",
3
3
  "type": "module",
4
- "version": "0.4.1",
4
+ "version": "0.5.1",
5
5
  "description": "A universal compiler for all Atomic Smash projects.",
6
6
  "keywords": [
7
7
  "cli",
@@ -44,19 +44,15 @@
44
44
  "lint:types": "tsc"
45
45
  },
46
46
  "dependencies": {
47
- "@babel/preset-env": "^7.26.0",
48
- "@babel/preset-react": "^7.26.3",
49
- "@babel/preset-typescript": "^7.26.0",
50
47
  "@wordpress/dependency-extraction-webpack-plugin": "^6.15.0",
51
- "babel-loader": "^9.2.1",
48
+ "browserslist-to-esbuild": "^2.1.1",
52
49
  "copy-webpack-plugin": "^12.0.2",
53
50
  "css-loader": "^7.1.2",
54
51
  "cssnano": "^7.0.6",
52
+ "esbuild-loader": "^4.3.0",
55
53
  "fast-glob": "^3.3.2",
56
54
  "postcss": "^8.4.49",
57
- "postcss-increase-specificity": "^0.6.0",
58
55
  "postcss-loader": "^8.1.1",
59
- "postcss-plugin-context": "^2.0.0",
60
56
  "postcss-preset-env": "^10.1.3",
61
57
  "sass": "^1.83.1",
62
58
  "sass-loader": "^16.0.4",