@atomicsmash/compiler 0.1.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/dist/css.d.ts +36 -0
- package/dist/css.d.ts.map +1 -0
- package/dist/css.js +33 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +257 -0
- package/package.json +75 -0
package/dist/css.d.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export declare const cssEntries = "css/*.css";
|
|
2
|
+
export declare const scssEntries = "css/*.s[ac]ss";
|
|
3
|
+
export declare const cssRules: (MODE: "production" | "development") => {
|
|
4
|
+
loader: string;
|
|
5
|
+
options: {
|
|
6
|
+
postcssOptions: {
|
|
7
|
+
sourceMap: boolean;
|
|
8
|
+
plugins: (string | (string | {
|
|
9
|
+
stage: number;
|
|
10
|
+
features: {
|
|
11
|
+
"custom-media-queries": boolean;
|
|
12
|
+
};
|
|
13
|
+
})[])[];
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
}[];
|
|
17
|
+
export declare const scssRules: (MODE: "production" | "development") => ({
|
|
18
|
+
loader: string;
|
|
19
|
+
options: {
|
|
20
|
+
postcssOptions: {
|
|
21
|
+
sourceMap: boolean;
|
|
22
|
+
plugins: (string | (string | {
|
|
23
|
+
stage: number;
|
|
24
|
+
features: {
|
|
25
|
+
"custom-media-queries": boolean;
|
|
26
|
+
};
|
|
27
|
+
})[])[];
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
} | {
|
|
31
|
+
loader: string;
|
|
32
|
+
options: {
|
|
33
|
+
sourceMap: boolean;
|
|
34
|
+
};
|
|
35
|
+
})[];
|
|
36
|
+
//# sourceMappingURL=css.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"css.d.ts","sourceRoot":"","sources":["../src/css.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,UAAU,cAAc,CAAC;AACtC,eAAO,MAAM,WAAW,kBAAkB,CAAC;AAC3C,eAAO,MAAM,QAAQ,SAAU,YAAY,GAAG,aAAa;;;;;;;;;;;;;GAqB1D,CAAC;AACF,eAAO,MAAM,SAAS,SAAU,YAAY,GAAG,aAAa;;;;;;;;;;;;;;;;;;IAQ3D,CAAC"}
|
package/dist/css.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export const cssEntries = `css/*.css`;
|
|
2
|
+
export const scssEntries = `css/*.s[ac]ss`;
|
|
3
|
+
export const cssRules = (MODE) => [
|
|
4
|
+
{
|
|
5
|
+
loader: "postcss-loader",
|
|
6
|
+
options: {
|
|
7
|
+
postcssOptions: {
|
|
8
|
+
sourceMap: MODE === "development",
|
|
9
|
+
plugins: [
|
|
10
|
+
[
|
|
11
|
+
"postcss-preset-env",
|
|
12
|
+
{
|
|
13
|
+
stage: 2,
|
|
14
|
+
features: {
|
|
15
|
+
"custom-media-queries": true,
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
],
|
|
19
|
+
...(MODE === "production" ? ["cssnano"] : []),
|
|
20
|
+
],
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
];
|
|
25
|
+
export const scssRules = (MODE) => [
|
|
26
|
+
...cssRules(MODE),
|
|
27
|
+
{
|
|
28
|
+
loader: "sass-loader",
|
|
29
|
+
options: {
|
|
30
|
+
sourceMap: MODE === "development",
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
];
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAkBA,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
ADDED
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { sep as pathSeparator, extname, resolve as resolvePath, } from "node:path";
|
|
3
|
+
import DependencyExtractionWebpackPlugin from "@wordpress/dependency-extraction-webpack-plugin";
|
|
4
|
+
import CopyPlugin from "copy-webpack-plugin";
|
|
5
|
+
import glob from "fast-glob";
|
|
6
|
+
import SVGSpritemapPlugin from "svg-spritemap-webpack-plugin";
|
|
7
|
+
import { TsconfigPathsPlugin } from "tsconfig-paths-webpack-plugin";
|
|
8
|
+
import webpack from "webpack";
|
|
9
|
+
import WebpackAssetsManifest from "webpack-assets-manifest";
|
|
10
|
+
import { BundleAnalyzerPlugin } from "webpack-bundle-analyzer";
|
|
11
|
+
import yargs from "yargs";
|
|
12
|
+
import { hideBin } from "yargs/helpers";
|
|
13
|
+
const argv = await yargs(hideBin(process.argv))
|
|
14
|
+
.options({
|
|
15
|
+
in: {
|
|
16
|
+
demandOption: true,
|
|
17
|
+
describe: "The directory where the source files can be found. Relative to cwd.",
|
|
18
|
+
type: "string",
|
|
19
|
+
},
|
|
20
|
+
out: {
|
|
21
|
+
demandOption: true,
|
|
22
|
+
describe: "The directory where the compiled files will out output. Relative to cwd.",
|
|
23
|
+
type: "string",
|
|
24
|
+
},
|
|
25
|
+
watch: {
|
|
26
|
+
boolean: true,
|
|
27
|
+
default: false,
|
|
28
|
+
describe: "Whether to watch the files in the source folder for changes and compile.",
|
|
29
|
+
},
|
|
30
|
+
analyse: {
|
|
31
|
+
boolean: true,
|
|
32
|
+
default: false,
|
|
33
|
+
describe: "See a report of the generated bundle once built.",
|
|
34
|
+
},
|
|
35
|
+
})
|
|
36
|
+
.showHelpOnFail(false, "Specify --help for available options")
|
|
37
|
+
.parse();
|
|
38
|
+
const MODE = process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test"
|
|
39
|
+
? "development"
|
|
40
|
+
: "production";
|
|
41
|
+
const srcFolder = resolvePath(argv.in);
|
|
42
|
+
const distFolder = resolvePath(argv.out);
|
|
43
|
+
const postCSSConfig = [
|
|
44
|
+
[
|
|
45
|
+
"postcss-preset-env",
|
|
46
|
+
{
|
|
47
|
+
stage: 2,
|
|
48
|
+
features: {
|
|
49
|
+
"custom-media-queries": true,
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
],
|
|
53
|
+
...(MODE === "production" ? ["cssnano"] : []),
|
|
54
|
+
];
|
|
55
|
+
const compiler = webpack({
|
|
56
|
+
devtool: MODE === "development" ? "source-map" : false,
|
|
57
|
+
mode: MODE,
|
|
58
|
+
experiments: {
|
|
59
|
+
outputModule: true,
|
|
60
|
+
},
|
|
61
|
+
entry: await glob([
|
|
62
|
+
`${srcFolder}/js/*.{js,ts}`,
|
|
63
|
+
`${srcFolder}/css/*.css`,
|
|
64
|
+
`${srcFolder}/css/*.s[ac]ss`,
|
|
65
|
+
]).then((paths) => {
|
|
66
|
+
const entryPoints = {};
|
|
67
|
+
paths.forEach((path) => {
|
|
68
|
+
const entryName = path.replace(srcFolder, "").replace(extname(path), "");
|
|
69
|
+
entryPoints[entryName] = {
|
|
70
|
+
import: path,
|
|
71
|
+
filename: `${path.replace(`${srcFolder}${pathSeparator}`, "").replace(extname(path), "")}${MODE === "production" ? `.[contenthash]` : ""}.js`,
|
|
72
|
+
};
|
|
73
|
+
});
|
|
74
|
+
return entryPoints;
|
|
75
|
+
}),
|
|
76
|
+
output: {
|
|
77
|
+
filename: "js/[name].[contenthash].js",
|
|
78
|
+
clean: true,
|
|
79
|
+
library: {
|
|
80
|
+
type: "modern-module",
|
|
81
|
+
},
|
|
82
|
+
module: true,
|
|
83
|
+
path: distFolder,
|
|
84
|
+
},
|
|
85
|
+
resolve: {
|
|
86
|
+
plugins: [new TsconfigPathsPlugin()],
|
|
87
|
+
extensions: [".tsx", ".ts", ".js", ".jsx"],
|
|
88
|
+
},
|
|
89
|
+
module: {
|
|
90
|
+
rules: [
|
|
91
|
+
{
|
|
92
|
+
test: /\.[jt]sx?$/,
|
|
93
|
+
use: {
|
|
94
|
+
loader: "babel-loader",
|
|
95
|
+
options: {
|
|
96
|
+
presets: [["@babel/preset-typescript"], ["@babel/preset-env"]],
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
exclude: /node_modules/,
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
test: /\.s[ac]ss$/i,
|
|
103
|
+
exclude: /node_modules/,
|
|
104
|
+
type: "asset/resource",
|
|
105
|
+
generator: {
|
|
106
|
+
binary: false,
|
|
107
|
+
filename: "css/[name].[contenthash].css",
|
|
108
|
+
},
|
|
109
|
+
use: [
|
|
110
|
+
{
|
|
111
|
+
loader: "postcss-loader",
|
|
112
|
+
options: {
|
|
113
|
+
postcssOptions: {
|
|
114
|
+
sourceMap: MODE === "development",
|
|
115
|
+
plugins: postCSSConfig,
|
|
116
|
+
},
|
|
117
|
+
},
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
loader: "sass-loader",
|
|
121
|
+
options: {
|
|
122
|
+
sourceMap: MODE === "development",
|
|
123
|
+
},
|
|
124
|
+
},
|
|
125
|
+
],
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
test: /\.css$/i,
|
|
129
|
+
exclude: /node_modules/,
|
|
130
|
+
type: "asset/resource",
|
|
131
|
+
generator: {
|
|
132
|
+
binary: false,
|
|
133
|
+
filename: "css/[name].[contenthash].css",
|
|
134
|
+
},
|
|
135
|
+
use: [
|
|
136
|
+
{
|
|
137
|
+
loader: "postcss-loader",
|
|
138
|
+
options: {
|
|
139
|
+
postcssOptions: {
|
|
140
|
+
sourceMap: MODE === "development",
|
|
141
|
+
plugins: postCSSConfig,
|
|
142
|
+
},
|
|
143
|
+
},
|
|
144
|
+
},
|
|
145
|
+
],
|
|
146
|
+
},
|
|
147
|
+
],
|
|
148
|
+
},
|
|
149
|
+
plugins: [
|
|
150
|
+
new webpack.ProgressPlugin(),
|
|
151
|
+
new WebpackAssetsManifest({
|
|
152
|
+
writeToDisk: true,
|
|
153
|
+
output: `${distFolder}/assets-manifest.json`,
|
|
154
|
+
customize(entry) {
|
|
155
|
+
if (entry.key === "spritemap.svg") {
|
|
156
|
+
return { key: "icons/sprite.svg", value: entry.value };
|
|
157
|
+
}
|
|
158
|
+
if (entry.key.startsWith("/")) {
|
|
159
|
+
return { key: entry.key.slice(1), value: entry.value };
|
|
160
|
+
}
|
|
161
|
+
if (entry.key === "assets.php" ||
|
|
162
|
+
entry.key.startsWith("fonts") ||
|
|
163
|
+
entry.key.startsWith("images")) {
|
|
164
|
+
return false;
|
|
165
|
+
}
|
|
166
|
+
return entry;
|
|
167
|
+
},
|
|
168
|
+
}),
|
|
169
|
+
new SVGSpritemapPlugin(`${srcFolder}/icons/*.svg`, {
|
|
170
|
+
output: {
|
|
171
|
+
filename: "icons/sprite.[contenthash].svg",
|
|
172
|
+
},
|
|
173
|
+
sprite: {
|
|
174
|
+
prefix: "",
|
|
175
|
+
generate: {
|
|
176
|
+
title: false,
|
|
177
|
+
},
|
|
178
|
+
},
|
|
179
|
+
}),
|
|
180
|
+
new CopyPlugin({
|
|
181
|
+
patterns: [
|
|
182
|
+
{
|
|
183
|
+
from: `${srcFolder}/fonts`,
|
|
184
|
+
to: "[path]fonts/[name][ext]",
|
|
185
|
+
noErrorOnMissing: true,
|
|
186
|
+
},
|
|
187
|
+
{
|
|
188
|
+
from: `${srcFolder}/images`,
|
|
189
|
+
to: "[path]images/[name][ext]",
|
|
190
|
+
noErrorOnMissing: true,
|
|
191
|
+
},
|
|
192
|
+
],
|
|
193
|
+
}),
|
|
194
|
+
...(argv.analyse ? [new BundleAnalyzerPlugin({})] : []),
|
|
195
|
+
new DependencyExtractionWebpackPlugin({
|
|
196
|
+
combineAssets: true,
|
|
197
|
+
}),
|
|
198
|
+
],
|
|
199
|
+
optimization: {
|
|
200
|
+
splitChunks: {
|
|
201
|
+
chunks: "all",
|
|
202
|
+
},
|
|
203
|
+
},
|
|
204
|
+
});
|
|
205
|
+
if (argv.watch) {
|
|
206
|
+
const watching = compiler.watch({
|
|
207
|
+
// Example
|
|
208
|
+
aggregateTimeout: 300,
|
|
209
|
+
poll: undefined,
|
|
210
|
+
}, (error, stats) => {
|
|
211
|
+
if (error) {
|
|
212
|
+
console.error(error.stack ?? error);
|
|
213
|
+
process.exitCode = 1;
|
|
214
|
+
watching.close((closeError) => {
|
|
215
|
+
console.error(closeError);
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
else if (stats) {
|
|
219
|
+
const info = stats.toJson();
|
|
220
|
+
if (stats.hasErrors()) {
|
|
221
|
+
console.error(info.errors);
|
|
222
|
+
}
|
|
223
|
+
if (stats.hasWarnings()) {
|
|
224
|
+
console.warn(info.warnings);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
});
|
|
228
|
+
process.on("SIGINT", function () {
|
|
229
|
+
watching.close((closeError) => {
|
|
230
|
+
console.error(closeError);
|
|
231
|
+
});
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
else {
|
|
235
|
+
compiler.run((error, stats) => {
|
|
236
|
+
if (error) {
|
|
237
|
+
console.error(error);
|
|
238
|
+
process.exitCode = 1;
|
|
239
|
+
}
|
|
240
|
+
else if (stats) {
|
|
241
|
+
const info = stats.toJson();
|
|
242
|
+
if (stats.hasErrors()) {
|
|
243
|
+
console.error(info.errors);
|
|
244
|
+
process.exitCode = 1;
|
|
245
|
+
}
|
|
246
|
+
if (stats.hasWarnings()) {
|
|
247
|
+
console.warn(info.warnings);
|
|
248
|
+
process.exitCode = 2;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
compiler.close((closeError) => {
|
|
252
|
+
if (closeError) {
|
|
253
|
+
process.exitCode = 1;
|
|
254
|
+
}
|
|
255
|
+
});
|
|
256
|
+
});
|
|
257
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@atomicsmash/compiler",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "0.1.0",
|
|
5
|
+
"description": "A universal compiler for all Atomic Smash projects.",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"cli",
|
|
8
|
+
"compiler",
|
|
9
|
+
"webpack"
|
|
10
|
+
],
|
|
11
|
+
"homepage": "https://www.atomicsmash.co.uk/",
|
|
12
|
+
"license": "GPL-3.0-or-later",
|
|
13
|
+
"author": {
|
|
14
|
+
"name": "Atomic Smash",
|
|
15
|
+
"email": "npm@atomicsmash.co.uk",
|
|
16
|
+
"url": "https://www.atomicsmash.co.uk/"
|
|
17
|
+
},
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "https://github.com/AtomicSmash/packages",
|
|
21
|
+
"directory": "packages/compiler"
|
|
22
|
+
},
|
|
23
|
+
"files": [
|
|
24
|
+
"./dist/**/*"
|
|
25
|
+
],
|
|
26
|
+
"main": "index",
|
|
27
|
+
"bin": {
|
|
28
|
+
"smash-compile": "./dist/index.js"
|
|
29
|
+
},
|
|
30
|
+
"types": "index",
|
|
31
|
+
"publishConfig": {
|
|
32
|
+
"access": "public"
|
|
33
|
+
},
|
|
34
|
+
"scripts": {
|
|
35
|
+
"dev": "tsc --build --watch tsconfig.build.json",
|
|
36
|
+
"build": "npm-run-all clean compile",
|
|
37
|
+
"clean": "del-cli ./dist/ *.tsbuildinfo",
|
|
38
|
+
"compile": "tsc --build tsconfig.build.json",
|
|
39
|
+
"test": "TZ=\"Europe/Istanbul\" vitest run",
|
|
40
|
+
"test:ui": "TZ=\"Europe/Istanbul\" vitest --ui",
|
|
41
|
+
"test:coverage": "TZ=\"Europe/Istanbul\" vitest run --coverage",
|
|
42
|
+
"lint": "run-p lint:*",
|
|
43
|
+
"lint:eslint": "eslint --cache --cache-location ./node_modules/.cache/eslint . --ext .js,.ts,.jsx,.tsx",
|
|
44
|
+
"lint:types": "tsc"
|
|
45
|
+
},
|
|
46
|
+
"dependencies": {
|
|
47
|
+
"@babel/preset-env": "^7.26.0",
|
|
48
|
+
"@babel/preset-typescript": "^7.26.0",
|
|
49
|
+
"@wordpress/dependency-extraction-webpack-plugin": "^6.15.0",
|
|
50
|
+
"babel-loader": "^9.2.1",
|
|
51
|
+
"copy-webpack-plugin": "^12.0.2",
|
|
52
|
+
"css-loader": "^7.1.2",
|
|
53
|
+
"cssnano": "^7.0.6",
|
|
54
|
+
"fast-glob": "^3.3.2",
|
|
55
|
+
"postcss": "^8.4.49",
|
|
56
|
+
"postcss-loader": "^8.1.1",
|
|
57
|
+
"postcss-preset-env": "^10.1.3",
|
|
58
|
+
"sass": "^1.83.1",
|
|
59
|
+
"sass-loader": "^16.0.4",
|
|
60
|
+
"style-loader": "^4.0.0",
|
|
61
|
+
"svg-spritemap-webpack-plugin": "^4.7.0",
|
|
62
|
+
"tsconfig-paths-webpack-plugin": "^4.2.0",
|
|
63
|
+
"webpack": "^5.97.1",
|
|
64
|
+
"webpack-assets-manifest": "^5.2.1",
|
|
65
|
+
"webpack-bundle-analyzer": "^4.10.2",
|
|
66
|
+
"yargs": "^17.7.2"
|
|
67
|
+
},
|
|
68
|
+
"devDependencies": {
|
|
69
|
+
"@types/svg-spritemap-webpack-plugin": "^4.4.4",
|
|
70
|
+
"@types/webpack": "^5.28.5",
|
|
71
|
+
"@types/webpack-assets-manifest": "^5.1.4",
|
|
72
|
+
"@types/webpack-bundle-analyzer": "^4.7.0",
|
|
73
|
+
"@types/yargs": "^17.0.33"
|
|
74
|
+
}
|
|
75
|
+
}
|