Skip to content

Commit

Permalink
feat: adding a manual way to pass arguments for WebPack plugin readin…
Browse files Browse the repository at this point in the history
…g browserslist
  • Loading branch information
wangbingying authored and wangbingying committed Feb 27, 2022
1 parent c44d86f commit 162bbf5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
13 changes: 13 additions & 0 deletions plugins/plugin-webpack/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Once added to the configuration, `@snowpack/plugin-webpack` will run automatical
- `manifest: boolean | string` - Enable generating a manifest file. The default value is `false`, the default file name is `./asset-manifest.json` if setting manifest to `true`. The relative path is resolved from the output directory.
- `htmlMinifierOptions: boolean | object` - [See below](#minify-html).
- `failOnWarnings: boolean` - Does fail the build when Webpack emits warnings. The default value is `false`.
- `browserslist: string[]` - Manually pass the browserslist configuration as an array if you don't want to read it from `package.json` by default.

#### Extending The Default Webpack Config

Expand Down Expand Up @@ -87,3 +88,15 @@ The default options are:
removeStyleLinkTypeAttributes: true,
}
```

#### Specify the browser env

The default browserslist configuration is: `>0.75%, not ie 11, not UCAndroid >0, not OperaMini all`.
You can specify it by pass a string array as below or config it in the `package.json` file

```js
{
browserslist: ['>0.75%', 'not ie 11', 'not UCAndroid >0', 'not OperaMini all']
}
```

2 changes: 1 addition & 1 deletion plugins/plugin-webpack/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ module.exports = function plugin(config, args = {}) {
async optimize({buildDirectory, log}) {
const buildOptions = config.buildOptions || {};
let baseUrl = buildOptions.baseUrl || '/';
const tempBuildManifest = JSON.parse(
const tempBuildManifest = Array.isArray(args.browserslist) ? { browserslist: args.browserslist} : JSON.parse(
await fs.readFileSync(path.join(config.root || process.cwd(), 'package.json'), {
encoding: 'utf-8',
}),
Expand Down

1 comment on commit 162bbf5

@benyasin
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

adding a manual way to pass arguments for WebPack plugin reading browserslist

Please sign in to comment.