Skip to content

Commit

Permalink
Create a browsers configuration ✍️
Browse files Browse the repository at this point in the history
It is better to have all the config inside the `sagui.config.js` file.
  • Loading branch information
pirelenito committed Apr 14, 2017
1 parent 84a42ab commit 60ef044
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 19 deletions.
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,30 @@ module.exports = {
}
```

### `browsers`

List of browsers using the [browserslist format](https://github.com/ai/browserslist) that the target build must support.

```js
// sagui.config.js
module.exports = {
browsers: [
'> 1%',
'last 2 versions',
'IE 10'
]
}
```

If not provided, the above default will be used instead.

This information is used to decide:

- JavaScript language features to transpile;
- CSS prefixes to append.

Internally Sagui uses [babel-preset-env](https://github.com/babel/babel-preset-env) and [autoprefixer](https://github.com/postcss/autoprefixer).

### `style.cssModules`

By default, styles compiled with Sagui will be output as [CSS Modules](https://github.com/css-modules), meaning they won't be global.
Expand Down
9 changes: 0 additions & 9 deletions spec/integration/index.integration-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,6 @@ describe('[integration] sagui', function () {
return sagui({ projectPath, action: actions.TEST_UNIT, coverage: true })
})

it('should have the browserslist configuration in package.json', () => {
const packageJSON = JSON.parse(fs.readFileSync(path.join(projectPath, 'package.json')))
expect(packageJSON.browserslist).to.eql([
'> 1%',
'Last 2 versions',
'IE 10'
])
})

it('should have an .gitignore, .flowconfig and .editorconfig file', () => {
fs.readFileSync(path.join(projectPath, '.gitignore'))
fs.readFileSync(path.join(projectPath, '.flowconfig'))
Expand Down
6 changes: 4 additions & 2 deletions src/configure-webpack/loaders/javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import actions from '../../actions'

export default {
name: 'javaScript',
configure ({ action, projectPath, javaScript = {}, coverage }) {
configure ({ action, projectPath, javaScript = {}, coverage, browsers }) {
return {
plugins: [
new HappyPack({
Expand All @@ -33,7 +33,9 @@ export default {
// Unfortunately we are bound to what UglifyJS
// currently supports as language features
// https://github.com/babel/babel-preset-env#targetsuglify
uglify: true
uglify: true,

browsers
}
}],
require.resolve('babel-preset-flow'),
Expand Down
4 changes: 2 additions & 2 deletions src/configure-webpack/loaders/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const defaultConfig = {
*/
export default {
name: 'style',
configure ({ action, optimize, pages = [], projectPath, style = {} }) {
configure ({ action, optimize, pages = [], projectPath, style = {}, browsers }) {
// Use null-loader during tests
// for better performance
if (action === actions.TEST_UNIT) {
Expand Down Expand Up @@ -96,7 +96,7 @@ export default {
options: {
postcss: {
plugins: () => [
autoprefixer,
autoprefixer({ browsers }),

// allow importing values (variables) between css modules
// see: https://github.com/css-modules/postcss-modules-values#usage
Expand Down
5 changes: 5 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ export { MissingPackageJSON, SaguiPath, InvalidSaguiConfig } from './load-projec

const DEFAULT_SAGUI_CONFIG = {
port: 3000,
browsers: [
'> 1%',
'Last 2 versions',
'IE 10'
],
saguiPath: path.join(__dirname, '../'),
optimize: false,
coverage: false,
Expand Down
6 changes: 6 additions & 0 deletions src/load-project-sagui-config.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ describe('load-project-sagui-config', () => {
})
})

it('browsers', () => {
validateConfig({
browsers: ['> 1%']
})
})

it('develop.proxy', () => {
validateConfig({
develop: {
Expand Down
7 changes: 1 addition & 6 deletions src/run/install/package-json.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@ export default function (projectPath) {

json.write(packagePath, {
...packageJSON,
scripts: updateNpmScripts(packageJSON.scripts),
browserslist: packageJSON.browserslist || [
'> 1%',
'Last 2 versions',
'IE 10'
]
scripts: updateNpmScripts(packageJSON.scripts)
})
}
4 changes: 4 additions & 0 deletions src/sagui-config-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
"description": "https://github.com/saguijs/sagui#additionalwebpackconfig",
"type": "object"
},
"browsers": {
"description": "https://github.com/saguijs/sagui#browsers",
"type": "array"
},
"develop": {
"description": "https://github.com/saguijs/sagui#developproxy",
"type": "object"
Expand Down

0 comments on commit 60ef044

Please sign in to comment.