Skip to content

Commit 8db82b6

Browse files
lukeeddevelopit
authored andcommitted
Respect "browserslist" config (#125)
* respect 'browserslist' config * fix babel: browsers-->targets.browsers * add “Custom Config” docs (WIP) * derp * derp x2 * 3rd time's the charm * add autoprefixer link
1 parent bf62766 commit 8db82b6

File tree

4 files changed

+36
-17
lines changed

4 files changed

+36
-17
lines changed

.editorconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ charset = utf-8
77
trim_trailing_whitespace = true
88
insert_final_newline = true
99

10-
[{*.json,.*rc,*.yml}]
10+
[{*.json,.*rc,*.yml,*.md}]
1111
indent_style = space
1212
indent_size = 2
1313

README.md

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
- Monitor your bundle/chunk sizes with built-in tracking
1515
- Automatic app mounting, debug helpers & Hot Module Replacement
1616
- In just **4.5kb** you get a productive environment:
17-
- [preact]
18-
- [preact-router]
19-
- 1.5kb of conditionally-loaded polyfills for [fetch](https://github.com/developit/unfetch) & [Promise](https://npm.im/promise-polyfill)
17+
- [preact]
18+
- [preact-router]
19+
- 1.5kb of conditionally-loaded polyfills for [fetch](https://github.com/developit/unfetch) & [Promise](https://npm.im/promise-polyfill)
2020

2121

2222
### Commands
@@ -79,8 +79,8 @@ $ preact serve
7979

8080
--dir Directory root to serve static files from. [default: "build"]
8181
--cwd The working directory in which to spawn a server. [default: .]
82-
--server Which server to run, or "config" to produce a firebase config.
83-
[options: "simplehttp2server", "superstatic", "config"] [default:"simplehttp2server"]
82+
--server Which server to run, or "config" to produce a firebase config.
83+
[options: "simplehttp2server", "superstatic", "config"] [default:"simplehttp2server"]
8484
--dest Directory or filename where firebase.json should be written
8585
(used for --server config) [default: -]
8686
--port, -p Port to start a server on [default: "8080"]
@@ -99,6 +99,27 @@ npm run serve -- --server config
9999
# Copy your static files to a server!
100100
```
101101

102+
### Custom Configuration
103+
104+
> **TL;DR** Currently in progress. See [#56](https://github.com/developit/preact-cli/pull/56)
105+
106+
#### Browserslist
107+
108+
You may customize your list of supported browser versions by declaring a [`"browserslist"`](https://github.com/ai/browserslist) key within your `package.json`. Changing these values will modify your JavaScript (via [`babel-preset-env`](https://github.com/babel/babel-preset-env#targetsbrowsers)) and your CSS (via [`autoprefixer`](https://github.com/postcss/autoprefixer)) output.
109+
110+
By default, `preact-cli` emulates the following config:
111+
112+
```js
113+
// package.json
114+
{
115+
"browserslist": [
116+
"> 1%",
117+
"IE >= 9",
118+
"last 2 versions"
119+
]
120+
}
121+
```
122+
102123

103124
[preact]: https://github.com/developit/preact
104125
[preact-router]: https://github.com/developit/preact-router

src/lib/babel-config.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,11 @@ export default (env, options={}) => ({
33
presets: [
44
[require.resolve('babel-preset-env'), {
55
loose: true,
6-
modules: options.modules || false,
76
uglify: true,
8-
browsers: env.browsers ? env.browsers.split() : [
9-
'> 1%',
10-
'Last 2 versions',
11-
'IE >= 9'
12-
],
7+
modules: options.modules || false,
8+
targets: {
9+
browsers: options.browsers
10+
},
1311
exclude: [
1412
'transform-regenerator',
1513
'transform-es2015-typeof-symbol'

src/lib/webpack-config.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,10 @@ export default env => {
5353
env.src = '.';
5454
}
5555

56-
env.pkg = readJson(resolve(cwd, 'package.json')) || {};
5756
env.manifest = readJson(src('manifest.json')) || {};
57+
env.pkg = readJson(resolve(cwd, 'package.json')) || {};
58+
59+
let browsers = env.pkg.browserslist || ['> 1%', 'last 2 versions', 'IE >= 9'];
5860

5961
return createConfig.vanilla([
6062
setContext(src('.')),
@@ -103,7 +105,7 @@ export default env => {
103105
enforce: 'pre',
104106
test: /\.jsx?$/,
105107
loader: 'babel-loader',
106-
options: createBabelConfig(env)
108+
options: createBabelConfig(env, { browsers })
107109
}
108110
]
109111
}
@@ -232,9 +234,7 @@ export default env => {
232234
new webpack.LoaderOptionsPlugin({
233235
options: {
234236
postcss: () => [
235-
autoprefixer({
236-
browsers: ['last 2 versions']
237-
})
237+
autoprefixer({ browsers })
238238
],
239239
context: resolve(cwd, env.src || 'src')
240240
}

0 commit comments

Comments
 (0)