Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 1 addition & 5 deletions src/lib/babel-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,8 @@ export default (env, options={}) => ({
[require.resolve('babel-preset-env'), {
loose: true,
modules: options.modules || false,
browsers: options.browsers,
Copy link
Collaborator

Choose a reason for hiding this comment

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

❤️ options.browsers - babel-config.js will be still usable as a babel preset!

However it should be: target: { browsers: [...] } like here (I've wanted to check what this does - I still don't know, but at least I've noticed it is passed differently 😛 )

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh yeah, nice catch! Looks like that should have always been target.browsers 👍

Sorry, I'm confused by your first sentence. Not sure what you mean.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Just that I really dig that you pass browsers via options 😛 . That means I'll still be able to us babel-config.js as a babel preset in #56 and use it like so: presets: [path.resolve(..., 'babel-config.js', { browsers: ... } ]

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, haha, great!

I'm thinking now, to answer my own question (below), that I need to respect any "babel" config inside the package.json.

With #56, how will users customize their babel options? I should account for that too.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Via .babelrc or package.json (or even by changing webpack babel-loader query). I don't think you have to worry about that at all because babel is so smart that it extends over this configuration, i.e. a .babelrcthat looks like this { plugins: ["my-awesome-plugin"] } will get everything applied from this file + 'my-awesome-plugin'.

In case of collisions stuff from .babelrc takes precedence over our internal settings (don't remember if options were merged tough, e.g. when env preset was declared stuff like loose: true was preserved or in this case browsers would be preserved)

uglify: true,
browsers: env.browsers ? env.browsers.split() : [
'> 1%',
'Last 2 versions',
'IE >= 9'
],
exclude: [
'transform-regenerator',
'transform-es2015-typeof-symbol'
Expand Down
10 changes: 5 additions & 5 deletions src/lib/webpack-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,10 @@ export default env => {
env.src = '.';
}

env.pkg = readJson(resolve(cwd, 'package.json')) || {};
env.manifest = readJson(src('manifest.json')) || {};
env.pkg = readJson(resolve(cwd, 'package.json')) || {};

let browsers = env.pkg.browserslist || ['> 1%', 'last 2 versions', 'IE >= 9'];

return createConfig.vanilla([
setContext(src('.')),
Expand Down Expand Up @@ -103,7 +105,7 @@ export default env => {
enforce: 'pre',
test: /\.jsx?$/,
loader: 'babel-loader',
options: createBabelConfig(env)
options: createBabelConfig(env, { browsers })
}
]
}
Expand Down Expand Up @@ -232,9 +234,7 @@ export default env => {
new webpack.LoaderOptionsPlugin({
options: {
postcss: () => [
autoprefixer({
browsers: ['last 2 versions']
})
autoprefixer({ browsers })
],
context: resolve(cwd, env.src || 'src')
}
Expand Down