@atomicsmash/compiler 0.5.0 → 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,5 +1,5 @@
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
4
  import browserslistToEsbuild from "browserslist-to-esbuild";
5
5
  import CopyPlugin from "copy-webpack-plugin";
@@ -64,10 +64,13 @@ 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
  }),
@@ -77,15 +80,22 @@ const postCSSConfig = [
77
80
  const compiler = webpack({
78
81
  resolveLoader: {
79
82
  modules: [
83
+ // Get modules from project node_modules folder
80
84
  "node_modules",
85
+ // Get modules from this package's internal node modules folder once installed
81
86
  resolvePath(import.meta.dirname, "../", "node_modules"),
82
87
  ],
83
88
  },
89
+ // Add sourcemaps in dev mode
84
90
  devtool: MODE === "development" ? "source-map" : false,
91
+ // Set the environment mode from NODE_ENV.
85
92
  mode: MODE,
86
93
  entry: await glob([
94
+ // Parse all direct children of the JS folder, as long as they are JS & TS files
87
95
  `${srcFolder}/js/*.{js,ts,jsx,tsx}`,
96
+ // Parse all direct children of the CSS folder, as long as they are CSS files
88
97
  `${srcFolder}/css/*.css`,
98
+ // Parse all nested children of the CSS folder, as long as they are non-partial SCSS files
89
99
  `${srcFolder}/css/**/[^_]*.s[ac]ss`,
90
100
  ]).then((paths) => {
91
101
  const entryPoints = {};
@@ -93,34 +103,45 @@ const compiler = webpack({
93
103
  const entryName = path.replace(srcFolder, "").replace(extname(path), "");
94
104
  entryPoints[entryName] = {
95
105
  import: path,
106
+ // Output filenames with content hash for fingerprinting
96
107
  filename: `${path.replace(`${srcFolder}${pathSeparator}`, "").replace(extname(path), "")}${MODE === "production" ? `.[contenthash]` : ""}.js`,
97
108
  };
98
109
  });
99
110
  return entryPoints;
100
111
  }),
101
112
  output: {
113
+ // Output filenames with content hash for fingerprinting
102
114
  filename: "js/[name].[contenthash].js",
115
+ // Clear files between runs
103
116
  clean: true,
104
117
  library: {
118
+ // Output JS files with Universal Module Definition
105
119
  type: "umd",
106
120
  },
121
+ // Set the output folder
107
122
  path: distFolder,
108
123
  },
109
124
  resolve: {
125
+ // support TSConfig paths as aliases
110
126
  plugins: [new TsconfigPathsPlugin()],
127
+ // resolve TS extensions
111
128
  extensions: [".tsx", ".ts", ".js", ".jsx"],
112
129
  },
113
130
  module: {
114
131
  rules: [
132
+ // Support Vue files if vue-loader is present
115
133
  ...vueConfig.loader,
134
+ // Use ESBuild loader to transpile JS & TS files
116
135
  {
117
136
  test: /\.[jt]sx?$/,
118
137
  use: {
119
138
  loader: "esbuild-loader",
120
139
  options: {
140
+ // Set target to match the browserslist config
121
141
  target: browserslistToEsbuild(),
122
142
  },
123
143
  },
144
+ // Exclude node_modules files from transpilation unless they are vue files and the vue-loader is present
124
145
  exclude: (file) => {
125
146
  if (vueConfig.loader.length > 0) {
126
147
  return file.includes("node_modules") && !file.includes(".vue.js");
@@ -128,6 +149,7 @@ const compiler = webpack({
128
149
  return file.includes("node_modules");
129
150
  },
130
151
  },
152
+ // Transpile SCSS files and run the result through postcss
131
153
  {
132
154
  test: /\.s[ac]ss$/i,
133
155
  exclude: /node_modules/,
@@ -154,6 +176,7 @@ const compiler = webpack({
154
176
  },
155
177
  ],
156
178
  },
179
+ // Run the css files through postcss
157
180
  {
158
181
  test: /\.css$/i,
159
182
  exclude: /node_modules/,
@@ -177,7 +200,9 @@ const compiler = webpack({
177
200
  ],
178
201
  },
179
202
  plugins: [
203
+ // Output progress information when compiling
180
204
  new webpack.ProgressPlugin(),
205
+ // Generate a manifest file of assets to make it possible to target fingerprinted files
181
206
  new WebpackAssetsManifest({
182
207
  writeToDisk: true,
183
208
  output: `${distFolder}/assets-manifest.json`,
@@ -196,6 +221,7 @@ const compiler = webpack({
196
221
  return entry;
197
222
  },
198
223
  }),
224
+ // Create an SVG sprite from a folder of provided icons
199
225
  new SVGSpritemapPlugin(`${srcFolder}/icons/*.svg`, {
200
226
  output: {
201
227
  filename: "icons/sprite.[contenthash].svg",
@@ -207,28 +233,39 @@ const compiler = webpack({
207
233
  },
208
234
  },
209
235
  }),
236
+ // Copy fonts and images from the src folder to assets (available for backwards compatibility, not recommended)
210
237
  new CopyPlugin({
211
238
  patterns: [
212
239
  {
213
- from: `${srcFolder}/fonts`,
214
- to: "[path]fonts/[name][ext]",
240
+ from: "**/*",
241
+ context: resolvePath(srcFolder, "fonts"),
242
+ to({ context, absoluteFilename }) {
243
+ return `fonts/${relative(context, absoluteFilename ?? "")}`;
244
+ },
215
245
  noErrorOnMissing: true,
216
246
  },
217
247
  {
218
- from: `${srcFolder}/images`,
219
- to: "[path]images/[name][ext]",
248
+ from: "**/*",
249
+ context: resolvePath(srcFolder, "images"),
250
+ to({ context, absoluteFilename }) {
251
+ return `images/${relative(context, absoluteFilename ?? "")}`;
252
+ },
220
253
  noErrorOnMissing: true,
221
254
  },
222
255
  ],
223
256
  }),
257
+ // Output a bundle analysis if flag was provided
224
258
  ...(argv.analyse ? [new BundleAnalyzerPlugin({})] : []),
259
+ // Extract wordpress dependencies from js files and output a wordpress assets file for enqueues
225
260
  new DependencyExtractionWebpackPlugin({
226
261
  combineAssets: true,
227
262
  }),
263
+ // Support Vue files if vue-loader is present
228
264
  ...vueConfig.plugin,
229
265
  ],
230
266
  optimization: {
231
267
  minimizer: [
268
+ // Minify JS files
232
269
  new EsbuildPlugin({
233
270
  target: browserslistToEsbuild(),
234
271
  }),
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@atomicsmash/compiler",
3
3
  "type": "module",
4
- "version": "0.5.0",
4
+ "version": "0.5.1",
5
5
  "description": "A universal compiler for all Atomic Smash projects.",
6
6
  "keywords": [
7
7
  "cli",