Skip to content

Commit 559190e

Browse files
authored
Merge pull request #1851 from SUI-Components/sui-bundler-creat-chunks-css-flag
Create --chunks-css flag
2 parents 23933a4 + bd3af7f commit 559190e

File tree

3 files changed

+62
-50
lines changed

3 files changed

+62
-50
lines changed

packages/sui-bundler/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,14 @@ $ sui-bundler lib src/index.js -o umd/fancy -p http://my-cdn.com/fancy --umd="My
151151

152152
Then you can find your library directly in the provided namespace variable: `window.MyFancyLibraryNamespace` or `window.MyFancyLibraryNamespace.default` for ES6 exports.
153153

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+
154162
## Configuration
155163

156164
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.

packages/sui-bundler/bin/sui-bundler-lib.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ program
1717
.option('-u, --umd [libraryName]', 'Whether to output library as umb')
1818
.option('-r, --root', 'Create build in root dir instead of version subdir')
1919
.option('-p, --path [path]', 'Absolute public path where files will be located.')
20+
.option('--chunk-css', 'Bundle css in chunks')
2021
.on('--help', () =>
2122
console.log(`Examples:
2223
$ sui-bundler lib src/index.js -o umd/my-lib -p http://my-cdn.com/my-lib -C'
@@ -27,7 +28,7 @@ program
2728

2829
const [entry] = program.args
2930
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
3132
const publicPath = options.path
3233

3334
if (!output) {
@@ -46,7 +47,7 @@ process.env.NODE_ENV = process.env.NODE_ENV || 'production'
4647

4748
const version = getPackageJson(process.cwd()).version
4849
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)}
5051
webpackConfig.output.publicPath = publicPath + (root ? '' : version + '/')
5152
webpackConfig.output.path = outputFolder
5253

packages/sui-bundler/webpack.config.lib.js

Lines changed: 51 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -9,55 +9,58 @@ const sassRules = require('./shared/module-rules-sass.js')
99
const {extractComments, sourceMap, supportLegacyBrowsers} = require('./shared/config.js')
1010
const {aliasFromConfig} = require('./shared/resolve-alias.js')
1111

12-
const cssFileName = 'styles.css'
13-
14-
module.exports = {
15-
mode: 'production',
16-
resolve: {
17-
alias: {
18-
...aliasFromConfig
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'
1940
},
20-
fallback: {
21-
assert: false,
22-
fs: false,
23-
http: require.resolve('stream-http'),
24-
https: require.resolve('https-browserify'),
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})]
2646
},
27-
extensions: ['.js', '.tsx', '.ts', '.json'],
28-
modules: ['node_modules', path.resolve(process.cwd())]
29-
},
30-
entry: config.vendor
31-
? {
32-
app: MAIN_ENTRY_POINT,
33-
vendor: config.vendor
34-
}
35-
: MAIN_ENTRY_POINT,
36-
target: 'web',
37-
output: {
38-
filename: 'index.js'
39-
},
40-
optimization: {
41-
// avoid looping over all the modules after the compilation
42-
checkWasmTypes: false,
43-
minimize: true,
44-
minimizer: [minifyJs({extractComments, sourceMap})]
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+
}
6265
}
6366
}

0 commit comments

Comments
 (0)