@nimbus-ds/webpack 1.1.0 → 1.2.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/config/alias.ts +25 -0
- package/dist/config/base.ts +42 -0
- package/dist/config/development.ts +15 -0
- package/dist/config/external.ts +22 -0
- package/dist/config/index.ts +6 -0
- package/dist/config/production.ts +19 -0
- package/dist/index.ts +43 -0
- package/dist/plugins/cssHashRemoverPlugin.ts +81 -0
- package/dist/plugins/cssMinimizerPlugin.ts +6 -0
- package/dist/plugins/dtsBundleGeneratorPlugin.ts +24 -0
- package/dist/plugins/index.ts +6 -0
- package/dist/plugins/miniCssExtract.ts +13 -0
- package/dist/plugins/terserJSPlugin.ts +11 -0
- package/dist/plugins/vanillaExtractPlugin.ts +8 -0
- package/dist/rules/common.ts +12 -0
- package/dist/rules/index.ts +3 -0
- package/dist/rules/styles.ts +20 -0
- package/dist/rules/svg.ts +8 -0
- package/dist/utils/constants.ts +15 -0
- package/dist/utils/helpers.ts +12 -0
- package/dist/utils/index.ts +2 -0
- package/package.json +7 -2
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Created by: Júnior Conquista (junior.conquista@nuvemshop.com.br)
|
|
3
|
+
* @see https://webpack.js.org/configuration/dev-server/
|
|
4
|
+
*/
|
|
5
|
+
import dashify from "dashify";
|
|
6
|
+
import glob from "glob";
|
|
7
|
+
import { join } from "path";
|
|
8
|
+
import { rootDir } from "../utils/constants";
|
|
9
|
+
|
|
10
|
+
const paths = glob.sync(`${join(rootDir, "./packages/react/src/*/*/src")}`);
|
|
11
|
+
|
|
12
|
+
const packages = paths.reduce((prev: { [key: string]: string }, curr) => {
|
|
13
|
+
const key = `@nimbus-ds/${dashify(curr.split("/")[10])}`;
|
|
14
|
+
prev[key] = curr;
|
|
15
|
+
return prev;
|
|
16
|
+
}, {});
|
|
17
|
+
|
|
18
|
+
export const aliasItems = {
|
|
19
|
+
"@nimbus-ds/icons": join(rootDir, "./packages/icons"),
|
|
20
|
+
"@nimbus-ds/tokens": join(rootDir, "./packages/core/tokens"),
|
|
21
|
+
"@nimbus-ds/typings": join(rootDir, "./packages/core/typings/src"),
|
|
22
|
+
"@nimbus-ds/styles": join(rootDir, "./packages/core/styles/src"),
|
|
23
|
+
"@nimbus-ds/webpack": join(rootDir, "./packages/core/webpack/src"),
|
|
24
|
+
...packages,
|
|
25
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Created by: Júnior Conquista (junior.conquista@nuvemshop.com.br)
|
|
3
|
+
*/
|
|
4
|
+
import merge from "webpack-merge";
|
|
5
|
+
import { Configuration } from "webpack";
|
|
6
|
+
|
|
7
|
+
import { arrayFilterEmpty, isProduction } from "../utils";
|
|
8
|
+
import { typescriptRule, svgRule } from "../rules";
|
|
9
|
+
import { dtsBundleGeneratorPlugin } from "../plugins";
|
|
10
|
+
import { aliasItems } from "./alias";
|
|
11
|
+
import { externalItems } from "./external";
|
|
12
|
+
|
|
13
|
+
import production from "./production";
|
|
14
|
+
import development from "./development";
|
|
15
|
+
|
|
16
|
+
const webpack: Configuration = {
|
|
17
|
+
target: "node",
|
|
18
|
+
mode: isProduction ? "production" : "development",
|
|
19
|
+
entry: {
|
|
20
|
+
"./index": "./src/index.ts",
|
|
21
|
+
},
|
|
22
|
+
output: {
|
|
23
|
+
filename: "[name].js",
|
|
24
|
+
libraryTarget: "umd",
|
|
25
|
+
},
|
|
26
|
+
module: {
|
|
27
|
+
rules: arrayFilterEmpty([typescriptRule, svgRule]),
|
|
28
|
+
},
|
|
29
|
+
plugins: [dtsBundleGeneratorPlugin()],
|
|
30
|
+
resolve: {
|
|
31
|
+
alias: aliasItems,
|
|
32
|
+
extensions: [".tsx", ".ts", ".js"],
|
|
33
|
+
},
|
|
34
|
+
externals: externalItems,
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export const getConfiguration = (config?: Configuration) =>
|
|
38
|
+
isProduction
|
|
39
|
+
? merge(webpack, production, config || {})
|
|
40
|
+
: merge(webpack, development, config || {});
|
|
41
|
+
|
|
42
|
+
export default getConfiguration();
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Created by: Júnior Conquista (junior.conquista@nuvemshop.com.br)
|
|
3
|
+
*/
|
|
4
|
+
import { Configuration } from "webpack";
|
|
5
|
+
import { terserJSPlugin } from "../plugins";
|
|
6
|
+
|
|
7
|
+
const webpack: Configuration = {
|
|
8
|
+
devtool: "source-map",
|
|
9
|
+
optimization: {
|
|
10
|
+
minimize: true,
|
|
11
|
+
minimizer: [terserJSPlugin],
|
|
12
|
+
},
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export default webpack;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Created by: Júnior Conquista (junior.conquista@nuvemshop.com.br)
|
|
3
|
+
* @see https://webpack.js.org/configuration/externals/
|
|
4
|
+
*/
|
|
5
|
+
export const externalLibs = {
|
|
6
|
+
"@floating-ui/react-dom-interactions": "@floating-ui/react-dom-interactions",
|
|
7
|
+
"@nimbus-ds/styles": "@nimbus-ds/styles",
|
|
8
|
+
react: "react",
|
|
9
|
+
"react-dom": "react-dom",
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export const externalPackages = {
|
|
13
|
+
"@nimbus-ds/icon": "@nimbus-ds/icon",
|
|
14
|
+
"@nimbus-ds/icons": "@nimbus-ds/icons",
|
|
15
|
+
"@nimbus-ds/skeleton": "@nimbus-ds/skeleton",
|
|
16
|
+
"@nimbus-ds/spinner": "@nimbus-ds/spinner",
|
|
17
|
+
"@nimbus-ds/text": "@nimbus-ds/text",
|
|
18
|
+
"@nimbus-ds/title": "@nimbus-ds/title",
|
|
19
|
+
"@nimbus-ds/tokens": "@nimbus-ds/tokens",
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export const externalItems = { ...externalLibs, ...externalPackages };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { getConfiguration, default as base } from "./base";
|
|
2
|
+
export { default as development } from "./development";
|
|
3
|
+
export { default as production } from "./production";
|
|
4
|
+
|
|
5
|
+
export { aliasItems } from "./alias";
|
|
6
|
+
export { externalItems, externalLibs, externalPackages } from "./external";
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Created by: Júnior Conquista (junior.conquista@nuvemshop.com.br)
|
|
3
|
+
*/
|
|
4
|
+
import { Configuration } from "webpack";
|
|
5
|
+
import { cssMinimizerPlugin, terserJSPlugin } from "../plugins";
|
|
6
|
+
|
|
7
|
+
const webpack: Configuration = {
|
|
8
|
+
optimization: {
|
|
9
|
+
minimize: true,
|
|
10
|
+
minimizer: [terserJSPlugin, cssMinimizerPlugin],
|
|
11
|
+
},
|
|
12
|
+
performance: {
|
|
13
|
+
hints: false,
|
|
14
|
+
maxEntrypointSize: 512000,
|
|
15
|
+
maxAssetSize: 512000,
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export default webpack;
|
package/dist/index.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getConfiguration,
|
|
3
|
+
development,
|
|
4
|
+
production,
|
|
5
|
+
base,
|
|
6
|
+
externalLibs,
|
|
7
|
+
} from "./config";
|
|
8
|
+
import {
|
|
9
|
+
vanillaExtractPlugin,
|
|
10
|
+
miniCssExtractPlugin,
|
|
11
|
+
dtsBundleGeneratorPlugin,
|
|
12
|
+
cssHashRemoverPlugin,
|
|
13
|
+
cssMinimizerPlugin,
|
|
14
|
+
} from "./plugins";
|
|
15
|
+
import { cssLoaderExtractRule, styleLoaderCssRule } from "./rules";
|
|
16
|
+
import { rootDir } from "./utils";
|
|
17
|
+
|
|
18
|
+
export const rules = { cssLoaderExtractRule, styleLoaderCssRule };
|
|
19
|
+
export const plugins = {
|
|
20
|
+
vanillaExtractPlugin,
|
|
21
|
+
miniCssExtractPlugin,
|
|
22
|
+
cssHashRemoverPlugin,
|
|
23
|
+
cssMinimizerPlugin,
|
|
24
|
+
dtsBundleGeneratorPlugin,
|
|
25
|
+
};
|
|
26
|
+
export const configuration = {
|
|
27
|
+
externalLibs,
|
|
28
|
+
development,
|
|
29
|
+
production,
|
|
30
|
+
base,
|
|
31
|
+
getConfiguration,
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export const utils = { rootDir };
|
|
35
|
+
|
|
36
|
+
const webpack = {
|
|
37
|
+
rules,
|
|
38
|
+
plugins,
|
|
39
|
+
configuration,
|
|
40
|
+
utils,
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export default webpack;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
type Compiler = import("webpack").Compiler;
|
|
2
|
+
|
|
3
|
+
class CssHashRemoverPlugin {
|
|
4
|
+
options;
|
|
5
|
+
|
|
6
|
+
content = "";
|
|
7
|
+
|
|
8
|
+
static defaultOptions = {
|
|
9
|
+
outputFile: "styles.css",
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
// Any options should be passed in the constructor of your plugin,
|
|
13
|
+
// (this is a public API of your plugin).
|
|
14
|
+
constructor(options = {}) {
|
|
15
|
+
// Applying user-specified options over the default options
|
|
16
|
+
// and making merged options further available to the plugin methods.
|
|
17
|
+
// You should probably validate all the options here as well.
|
|
18
|
+
this.options = { ...CssHashRemoverPlugin.defaultOptions, ...options };
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
apply(compiler: Compiler) {
|
|
22
|
+
const pluginName = CssHashRemoverPlugin.name;
|
|
23
|
+
|
|
24
|
+
// webpack module instance can be accessed from the compiler object,
|
|
25
|
+
// this ensures that correct version of the module is used
|
|
26
|
+
// (do not require/import the webpack or any symbols from it directly).
|
|
27
|
+
const { webpack } = compiler;
|
|
28
|
+
|
|
29
|
+
// Compilation object gives us reference to some useful constants.
|
|
30
|
+
const { Compilation } = webpack;
|
|
31
|
+
|
|
32
|
+
// RawSource is one of the "sources" classes that should be used
|
|
33
|
+
// to represent asset sources in compilation.
|
|
34
|
+
const { RawSource } = webpack.sources;
|
|
35
|
+
|
|
36
|
+
// Tapping to the "thisCompilation" hook in order to further tap
|
|
37
|
+
// to the compilation process on an earlier stage.
|
|
38
|
+
compiler.hooks.thisCompilation.tap(pluginName, (compilation) => {
|
|
39
|
+
// Tapping to the assets processing pipeline on a specific stage.
|
|
40
|
+
compilation.hooks.processAssets.tap(
|
|
41
|
+
{
|
|
42
|
+
name: pluginName,
|
|
43
|
+
// Using one of the later asset processing stages to ensure
|
|
44
|
+
// that all assets were already added to the compilation by other plugins.
|
|
45
|
+
stage: Compilation.PROCESS_ASSETS_STAGE_SUMMARIZE,
|
|
46
|
+
},
|
|
47
|
+
(assets) => {
|
|
48
|
+
const source = assets?.["./index.css"]?.source()?.toString() ?? "";
|
|
49
|
+
const matches = Array.from(
|
|
50
|
+
source?.matchAll(
|
|
51
|
+
/(?:\.nimbus-[\w|-]+)(?:(__\w{7,}))(?::{0,2}(?:disabled|focus|active|hover|placeholder|focus-visible|after)?) ?{/gm
|
|
52
|
+
),
|
|
53
|
+
(m) => m[1]
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
const uniqueMatches = [...new Set(matches)];
|
|
57
|
+
|
|
58
|
+
this.content = source;
|
|
59
|
+
uniqueMatches?.forEach((hash) => {
|
|
60
|
+
const regex = new RegExp(`${hash}\\b`, "gm");
|
|
61
|
+
this.content = this.content.replace(regex, "");
|
|
62
|
+
});
|
|
63
|
+
// "assets" is an object that contains all assets
|
|
64
|
+
// in the compilation, the keys of the object are pathnames of the assets
|
|
65
|
+
// and the values are file sources.
|
|
66
|
+
|
|
67
|
+
// Iterating over all the assets and
|
|
68
|
+
// generating content for our Markdown file.
|
|
69
|
+
// Adding new asset to the compilation, so it would be automatically
|
|
70
|
+
// generated by the webpack in the output directory.
|
|
71
|
+
compilation.emitAsset(
|
|
72
|
+
this.options.outputFile,
|
|
73
|
+
new RawSource(this.content)
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
);
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export const cssHashRemoverPlugin = new CssHashRemoverPlugin();
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Created by: Júnior Conquista (junior.conquista@nuvemshop.com.br)
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import WebpackShellPluginNextPlugin from "webpack-shell-plugin-next";
|
|
6
|
+
import { rootDir } from "../utils";
|
|
7
|
+
|
|
8
|
+
const entry = [
|
|
9
|
+
`node ${rootDir}/node_modules/.bin/dts-bundle-generator -o ./dist/index.d.ts ./src/index.ts`,
|
|
10
|
+
];
|
|
11
|
+
|
|
12
|
+
export const dtsBundleGeneratorPlugin = (
|
|
13
|
+
configuration: { entries: string[] } = { entries: entry }
|
|
14
|
+
) => {
|
|
15
|
+
const config = {
|
|
16
|
+
onBuildEnd: {
|
|
17
|
+
scripts: [...configuration.entries],
|
|
18
|
+
blocking: false,
|
|
19
|
+
parallel: true,
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
return new WebpackShellPluginNextPlugin(config);
|
|
24
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { miniCssExtractPlugin } from "./miniCssExtract";
|
|
2
|
+
export { vanillaExtractPlugin } from "./vanillaExtractPlugin";
|
|
3
|
+
export { cssHashRemoverPlugin } from "./cssHashRemoverPlugin";
|
|
4
|
+
export { cssMinimizerPlugin } from "./cssMinimizerPlugin";
|
|
5
|
+
export { terserJSPlugin } from "./terserJSPlugin";
|
|
6
|
+
export { dtsBundleGeneratorPlugin } from "./dtsBundleGeneratorPlugin";
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Created by: Júnior Conquista (junior.conquista@nuvemshop.com.br)
|
|
3
|
+
*/
|
|
4
|
+
import MiniCssExtractPlugin from "mini-css-extract-plugin";
|
|
5
|
+
|
|
6
|
+
const config = {
|
|
7
|
+
// Options similar to the same options in webpackOptions.output
|
|
8
|
+
// both options are optional
|
|
9
|
+
filename: "[name].css",
|
|
10
|
+
chunkFilename: "[id].css",
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export const miniCssExtractPlugin = new MiniCssExtractPlugin(config);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Created by: Júnior Conquista (junior.conquista@nuvemshop.com.br)
|
|
3
|
+
*/
|
|
4
|
+
import TerserJSPlugin from "terser-webpack-plugin";
|
|
5
|
+
|
|
6
|
+
const config = {
|
|
7
|
+
// Options similar to the same options in webpackOptions.output
|
|
8
|
+
// both options are optional
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export const terserJSPlugin = new TerserJSPlugin(config);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Created by: Júnior Conquista (junior.conquista@nuvemshop.com.br)
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @see https://webpack.js.org/guides/typescript/#loader
|
|
7
|
+
*/
|
|
8
|
+
export const typescriptRule = {
|
|
9
|
+
test: /\.tsx?$/,
|
|
10
|
+
loader: "ts-loader",
|
|
11
|
+
exclude: /node_modules/,
|
|
12
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Created by: Júnior Conquista (junior.conquista@nuvemshop.com.br)
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import MiniCssExtractPlugin from "mini-css-extract-plugin";
|
|
6
|
+
|
|
7
|
+
export const miniCssExtractRule = {
|
|
8
|
+
test: /\.css$/,
|
|
9
|
+
loader: MiniCssExtractPlugin.loader,
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export const cssLoaderExtractRule = {
|
|
13
|
+
test: /\.css$/i,
|
|
14
|
+
use: [MiniCssExtractPlugin.loader, "css-loader"],
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export const styleLoaderCssRule = {
|
|
18
|
+
test: /\.css$/i,
|
|
19
|
+
use: ["style-loader", "css-loader"],
|
|
20
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Created by: Júnior Conquista (junior.conquista@nuvemshop.com.br)
|
|
3
|
+
*/
|
|
4
|
+
import { join } from "path";
|
|
5
|
+
import * as dotenv from "dotenv"; // see https://github.com/motdotla/dotenv#how-do-i-use-dotenv-with-import
|
|
6
|
+
|
|
7
|
+
dotenv.config({
|
|
8
|
+
path: join(__dirname, "../../../../../.env"),
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
export const mode = process.env.NODE_ENV ?? "production";
|
|
12
|
+
export const isProduction = mode === "production";
|
|
13
|
+
export const isDevelopment = !isProduction;
|
|
14
|
+
export const rootDir = join(__dirname, "../../../../../");
|
|
15
|
+
export const webpackDir = join(__dirname, "../../");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nimbus-ds/webpack",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"files": [
|
|
@@ -8,6 +8,11 @@
|
|
|
8
8
|
"README.md"
|
|
9
9
|
],
|
|
10
10
|
"sideEffects": false,
|
|
11
|
+
"scripts": {
|
|
12
|
+
"build": "yarn clean && mkdir dist && cp -R src/* dist",
|
|
13
|
+
"clean": "rm -rf dist",
|
|
14
|
+
"g:webpack": "cd $INIT_CWD && webpack"
|
|
15
|
+
},
|
|
11
16
|
"homepage": "https://nimbus.nuvemshop.com.br/documentation",
|
|
12
17
|
"repository": {
|
|
13
18
|
"type": "git",
|
|
@@ -26,7 +31,7 @@
|
|
|
26
31
|
"mini-css-extract-plugin": "^2.7.2",
|
|
27
32
|
"terser-webpack-plugin": "^5.3.6",
|
|
28
33
|
"typescript": "^4.9.3",
|
|
29
|
-
"webpack": "^5.
|
|
34
|
+
"webpack": "^5.76.0",
|
|
30
35
|
"webpack-merge": "^5.8.0",
|
|
31
36
|
"webpack-shell-plugin-next": "^2.3.1"
|
|
32
37
|
}
|