Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: adding a manual way to pass arguments for WebPack plugin reading browserslist #3877

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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