@s-ui/bundler 9.67.0 → 9.69.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/README.md +53 -0
- package/bin/sui-bundler-lib.js +3 -2
- package/package.json +5 -4
- package/shared/svg-spritemap.js +12 -0
- package/webpack.config.client.dev.js +3 -1
- package/webpack.config.lib.js +51 -48
- package/webpack.config.prod.js +3 -1
package/README.md
CHANGED
|
@@ -151,6 +151,14 @@ $ sui-bundler lib src/index.js -o umd/fancy -p http://my-cdn.com/fancy --umd="My
|
|
|
151
151
|
|
|
152
152
|
Then you can find your library directly in the provided namespace variable: `window.MyFancyLibraryNamespace` or `window.MyFancyLibraryNamespace.default` for ES6 exports.
|
|
153
153
|
|
|
154
|
+
#### Use css chunks
|
|
155
|
+
|
|
156
|
+
You can use `--chunk-css` option for creating different chunks for each css file
|
|
157
|
+
|
|
158
|
+
```
|
|
159
|
+
$ sui-bundler lib src/index.js -o umd/fancy -p http://my-cdn.com/fancy --chunk-css
|
|
160
|
+
```
|
|
161
|
+
|
|
154
162
|
## Configuration
|
|
155
163
|
|
|
156
164
|
This tool works with zero configuration out the box but you could use some configuration in order to optimize or adapt the output to your needs. For that, you need to add a property `sui-bundler` inside a `config` property in the package.json of your project.
|
|
@@ -227,6 +235,51 @@ There are two ways to activate the statics cache option:
|
|
|
227
235
|
|
|
228
236
|
> Statics will be cached but no offline page will be activated
|
|
229
237
|
|
|
238
|
+
### SVG Spritemaps
|
|
239
|
+
|
|
240
|
+
Generate SVG spritemaps by using [svg-spritemap-webpack-plugin](https://github.com/cascornelissen/svg-spritemap-webpack-plugin) as follows:
|
|
241
|
+
|
|
242
|
+
```json
|
|
243
|
+
{
|
|
244
|
+
"sui-bundler": {
|
|
245
|
+
"spritemaps": [
|
|
246
|
+
{
|
|
247
|
+
"path": ["icons/src/fotocasa/**/*.svg"],
|
|
248
|
+
"options": {
|
|
249
|
+
"output": {
|
|
250
|
+
"filename": "fotocasa.[contenthash].svg",
|
|
251
|
+
"chunk": {
|
|
252
|
+
"name": "fotocasa"
|
|
253
|
+
}
|
|
254
|
+
},
|
|
255
|
+
"sprite": {
|
|
256
|
+
"generate": {
|
|
257
|
+
"title": false
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
},
|
|
262
|
+
{
|
|
263
|
+
"path": ["icons/src/habitaclia/**/*.svg"],
|
|
264
|
+
"options": {
|
|
265
|
+
"output": {
|
|
266
|
+
"filename": "habitaclia.[contenthash].svg",
|
|
267
|
+
"chunk": {
|
|
268
|
+
"name": "habitaclia"
|
|
269
|
+
}
|
|
270
|
+
},
|
|
271
|
+
"sprite": {
|
|
272
|
+
"generate": {
|
|
273
|
+
"title": false
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
]
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
```
|
|
282
|
+
|
|
230
283
|
## Externals Manifest
|
|
231
284
|
|
|
232
285
|
If your are using an external CDN to store statics assets that are now managed by Webpack, like SVG or IMGs, you can create a manifest.json file in the root of your CDN (likehttps://spa-mock-statics.surge.sh/manifest.json`).
|
package/bin/sui-bundler-lib.js
CHANGED
|
@@ -17,6 +17,7 @@ program
|
|
|
17
17
|
.option('-u, --umd [libraryName]', 'Whether to output library as umb')
|
|
18
18
|
.option('-r, --root', 'Create build in root dir instead of version subdir')
|
|
19
19
|
.option('-p, --path [path]', 'Absolute public path where files will be located.')
|
|
20
|
+
.option('--chunk-css', 'Bundle css in chunks')
|
|
20
21
|
.on('--help', () =>
|
|
21
22
|
console.log(`Examples:
|
|
22
23
|
$ sui-bundler lib src/index.js -o umd/my-lib -p http://my-cdn.com/my-lib -C'
|
|
@@ -27,7 +28,7 @@ program
|
|
|
27
28
|
|
|
28
29
|
const [entry] = program.args
|
|
29
30
|
const options = program.opts()
|
|
30
|
-
const {clean = false, output, umd = false, root = false} = options
|
|
31
|
+
const {clean = false, output, umd = false, root = false, chunkCss = false} = options
|
|
31
32
|
const publicPath = options.path
|
|
32
33
|
|
|
33
34
|
if (!output) {
|
|
@@ -46,7 +47,7 @@ process.env.NODE_ENV = process.env.NODE_ENV || 'production'
|
|
|
46
47
|
|
|
47
48
|
const version = getPackageJson(process.cwd()).version
|
|
48
49
|
const outputFolder = path.join(process.cwd(), output, path.sep, root ? '' : version)
|
|
49
|
-
const webpackConfig = {...config, entry: path.resolve(process.cwd(), entry)}
|
|
50
|
+
const webpackConfig = {...config({chunkCss}), entry: path.resolve(process.cwd(), entry)}
|
|
50
51
|
webpackConfig.output.publicPath = publicPath + (root ? '' : version + '/')
|
|
51
52
|
webpackConfig.output.path = outputFolder
|
|
52
53
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@s-ui/bundler",
|
|
3
|
-
"version": "9.
|
|
3
|
+
"version": "9.69.0",
|
|
4
4
|
"description": "Config-free bundler for ES6 React apps.",
|
|
5
5
|
"bin": {
|
|
6
6
|
"sui-bundler": "./bin/sui-bundler.js"
|
|
@@ -45,20 +45,21 @@
|
|
|
45
45
|
"html-webpack-plugin": "5.5.0",
|
|
46
46
|
"https-browserify": "1.0.0",
|
|
47
47
|
"mini-css-extract-plugin": "2.7.7",
|
|
48
|
-
"postcss-loader": "7.3.4",
|
|
49
48
|
"postcss": "8.4.31",
|
|
49
|
+
"postcss-loader": "7.3.4",
|
|
50
50
|
"process": "0.11.10",
|
|
51
51
|
"react-refresh": "0.14.0",
|
|
52
52
|
"sass": "1.54.5",
|
|
53
53
|
"stream-http": "3.2.0",
|
|
54
54
|
"strip-ansi": "6.0.1",
|
|
55
55
|
"style-loader": "3.3.4",
|
|
56
|
+
"svg-spritemap-webpack-plugin": "4.6.0",
|
|
56
57
|
"swc-loader": "0.2.6",
|
|
57
58
|
"tailwindcss": "3.4.14",
|
|
58
59
|
"url": "0.11.0",
|
|
60
|
+
"webpack": "5.82.1",
|
|
59
61
|
"webpack-dev-server": "5.0.4",
|
|
60
62
|
"webpack-manifest-plugin": "5.0.0",
|
|
61
|
-
"webpack-node-externals": "3.0.0"
|
|
62
|
-
"webpack": "5.82.1"
|
|
63
|
+
"webpack-node-externals": "3.0.0"
|
|
63
64
|
}
|
|
64
65
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
const SVGSpritemapPlugin = require('svg-spritemap-webpack-plugin')
|
|
2
|
+
const {config} = require('./config.js')
|
|
3
|
+
|
|
4
|
+
const createSVGSpritemapPlugin = () => {
|
|
5
|
+
const {spritemaps = []} = config
|
|
6
|
+
|
|
7
|
+
return spritemaps.map(({path, options = {}}) => {
|
|
8
|
+
return new SVGSpritemapPlugin(path, options)
|
|
9
|
+
})
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
module.exports = createSVGSpritemapPlugin
|
|
@@ -12,6 +12,7 @@ const {withHydrationOverlayWebpack} = require('@builder.io/react-hydration-overl
|
|
|
12
12
|
const {envVars, MAIN_ENTRY_POINT, config, cleanList, when, isTailwindEnabled} = require('./shared/index.js')
|
|
13
13
|
const definePlugin = require('./shared/define.js')
|
|
14
14
|
const manifestLoaderRules = require('./shared/module-rules-manifest-loader.js')
|
|
15
|
+
const createSVGSpritemapPlugin = require('./shared/svg-spritemap')
|
|
15
16
|
const {aliasFromConfig, defaultAlias} = require('./shared/resolve-alias.js')
|
|
16
17
|
const {supportLegacyBrowsers, cacheDirectory} = require('./shared/config.js')
|
|
17
18
|
|
|
@@ -88,7 +89,8 @@ const webpackConfig = {
|
|
|
88
89
|
new ReactRefreshWebpackPlugin({overlay: false}),
|
|
89
90
|
new HtmlWebpackInjectAttributesPlugin({
|
|
90
91
|
crossorigin: 'anonymous'
|
|
91
|
-
})
|
|
92
|
+
}),
|
|
93
|
+
...createSVGSpritemapPlugin()
|
|
92
94
|
],
|
|
93
95
|
resolveLoader,
|
|
94
96
|
module: {
|
package/webpack.config.lib.js
CHANGED
|
@@ -9,55 +9,58 @@ const sassRules = require('./shared/module-rules-sass.js')
|
|
|
9
9
|
const {extractComments, sourceMap, supportLegacyBrowsers} = require('./shared/config.js')
|
|
10
10
|
const {aliasFromConfig} = require('./shared/resolve-alias.js')
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
12
|
+
module.exports = ({chunkCss} = {}) => {
|
|
13
|
+
const chunkCssName = config.onlyHash ? '[contenthash:8].css' : '[name].[contenthash:8].css'
|
|
14
|
+
const cssFileName = chunkCss ? chunkCssName : 'styles.css'
|
|
15
|
+
return {
|
|
16
|
+
mode: 'production',
|
|
17
|
+
resolve: {
|
|
18
|
+
alias: {
|
|
19
|
+
...aliasFromConfig
|
|
20
|
+
},
|
|
21
|
+
fallback: {
|
|
22
|
+
assert: false,
|
|
23
|
+
fs: false,
|
|
24
|
+
http: require.resolve('stream-http'),
|
|
25
|
+
https: require.resolve('https-browserify'),
|
|
26
|
+
path: false
|
|
27
|
+
},
|
|
28
|
+
extensions: ['.js', '.tsx', '.ts', '.json'],
|
|
29
|
+
modules: ['node_modules', path.resolve(process.cwd())]
|
|
30
|
+
},
|
|
31
|
+
entry: config.vendor
|
|
32
|
+
? {
|
|
33
|
+
app: MAIN_ENTRY_POINT,
|
|
34
|
+
vendor: config.vendor
|
|
35
|
+
}
|
|
36
|
+
: MAIN_ENTRY_POINT,
|
|
37
|
+
target: 'web',
|
|
38
|
+
output: {
|
|
39
|
+
filename: 'index.js'
|
|
19
40
|
},
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
path: false
|
|
41
|
+
optimization: {
|
|
42
|
+
// avoid looping over all the modules after the compilation
|
|
43
|
+
checkWasmTypes: false,
|
|
44
|
+
minimize: true,
|
|
45
|
+
minimizer: [minifyJs({extractComments, sourceMap})]
|
|
26
46
|
},
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
},
|
|
46
|
-
plugins: cleanList([
|
|
47
|
-
new webpack.ProvidePlugin({
|
|
48
|
-
process: 'process/browser.js'
|
|
49
|
-
}),
|
|
50
|
-
new MiniCssExtractPlugin({
|
|
51
|
-
filename: cssFileName,
|
|
52
|
-
chunkFilename: cssFileName
|
|
53
|
-
}),
|
|
54
|
-
new webpack.optimize.LimitChunkCountPlugin({
|
|
55
|
-
maxChunks: 1
|
|
56
|
-
}),
|
|
57
|
-
new webpack.EnvironmentPlugin(envVars(config.env)),
|
|
58
|
-
definePlugin()
|
|
59
|
-
]),
|
|
60
|
-
module: {
|
|
61
|
-
rules: [createCompilerRules({supportLegacyBrowsers}), sassRules]
|
|
47
|
+
plugins: cleanList([
|
|
48
|
+
new webpack.ProvidePlugin({
|
|
49
|
+
process: 'process/browser.js'
|
|
50
|
+
}),
|
|
51
|
+
new MiniCssExtractPlugin({
|
|
52
|
+
filename: cssFileName,
|
|
53
|
+
chunkFilename: cssFileName
|
|
54
|
+
}),
|
|
55
|
+
!chunkCss &&
|
|
56
|
+
new webpack.optimize.LimitChunkCountPlugin({
|
|
57
|
+
maxChunks: 1
|
|
58
|
+
}),
|
|
59
|
+
new webpack.EnvironmentPlugin(envVars(config.env)),
|
|
60
|
+
definePlugin()
|
|
61
|
+
]),
|
|
62
|
+
module: {
|
|
63
|
+
rules: [createCompilerRules({supportLegacyBrowsers}), sassRules]
|
|
64
|
+
}
|
|
62
65
|
}
|
|
63
66
|
}
|
package/webpack.config.prod.js
CHANGED
|
@@ -15,6 +15,7 @@ const {extractComments, sourceMap, supportLegacyBrowsers, cacheDirectory} = requ
|
|
|
15
15
|
const {resolveLoader} = require('./shared/resolve-loader.js')
|
|
16
16
|
const createCompilerRules = require('./shared/module-rules-compiler.js')
|
|
17
17
|
const sassRules = require('./shared/module-rules-sass.js')
|
|
18
|
+
const createSVGSpritemapPlugin = require('./shared/svg-spritemap')
|
|
18
19
|
const definePlugin = require('./shared/define.js')
|
|
19
20
|
const manifestLoaderRules = require('./shared/module-rules-manifest-loader.js')
|
|
20
21
|
const minifyCss = require('./shared/minify-css.js')
|
|
@@ -100,7 +101,8 @@ const webpackConfig = {
|
|
|
100
101
|
template: './index.html'
|
|
101
102
|
}),
|
|
102
103
|
new InlineChunkHtmlPlugin(HtmlWebpackPlugin, [/runtime/]),
|
|
103
|
-
new WebpackManifestPlugin({fileName: 'asset-manifest.json'})
|
|
104
|
+
new WebpackManifestPlugin({fileName: 'asset-manifest.json'}),
|
|
105
|
+
...createSVGSpritemapPlugin()
|
|
104
106
|
]),
|
|
105
107
|
module: {
|
|
106
108
|
rules: cleanList([
|