From 162bbf5541a62f777728b805595a183382ba2e5c Mon Sep 17 00:00:00 2001 From: wangbingying Date: Sun, 27 Feb 2022 15:23:00 +0800 Subject: [PATCH] feat: adding a manual way to pass arguments for WebPack plugin reading browserslist --- plugins/plugin-webpack/README.md | 13 +++++++++++++ plugins/plugin-webpack/plugin.js | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/plugins/plugin-webpack/README.md b/plugins/plugin-webpack/README.md index a5ffc2ef50..e627fb2e6d 100644 --- a/plugins/plugin-webpack/README.md +++ b/plugins/plugin-webpack/README.md @@ -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 @@ -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'] +} +``` + diff --git a/plugins/plugin-webpack/plugin.js b/plugins/plugin-webpack/plugin.js index 0bfc5d2fab..95245af390 100644 --- a/plugins/plugin-webpack/plugin.js +++ b/plugins/plugin-webpack/plugin.js @@ -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', }),