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

fix: minifier plugin, babel-config update #36

Merged
merged 1 commit into from
Oct 19, 2020
Merged
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
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Maintenance Status: Stable
- [`NO_TEST_BUNDLE`](#no_test_bundle)
- [Function Options](#function-options)
- [`input`](#input)
- [`minifierPlugin`](#minifierplugin)
- [`testInput`](#testinput)
- [`distName`](#distname)
- [`exportName`](#exportname)
Expand Down Expand Up @@ -102,6 +103,13 @@ options that are passed as an object to the `generateRollupConfig` function.
The entry point for your build.

### `minifierPlugin`

> Type: `string`
> Default: `uglify`
The name of the primed plugin to use when minifying

### `testInput`

> Type: `string`
Expand Down Expand Up @@ -430,3 +438,4 @@ const defaultPrimedPlugins = {
uglify: uglify({output: {comments: 'some'}}, minify)
};
```
28 changes: 24 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ const ORDERED_DEFAULTS = {
'resolve',
'json',
'commonjs',
'uglify',
'babel'
],
module: [
Expand All @@ -113,10 +112,20 @@ const ORDERED_DEFAULTS = {
babel(settings) {
const config = Object.assign({}, babelConfig);

config.presets[0][1].targets.browsers = settings.browserslist;
config.babelHelpers = 'runtime';
config.skipPreflightCheck = true;

// change settings.browserslist to configured
for (let i = 0; i < config.presets.length; i++) {
if (!Array.isArray(config.presets[i])) {
continue;
}

if ((/@babel\/preset-env/).test(config.presets[i][0])) {
config.presets[i][1].targets.browsers = settings.browserslist;
}
}

return config;
},
excludeCoverage: () => ['test/**', path.join(__dirname, '**'), 'node_modules/**', 'package.json'],
Expand Down Expand Up @@ -161,7 +170,8 @@ const getSettings = function(options) {
browserslist: pkg.browserslist || ['defaults', 'ie 11'],
checkWatch: true,
banner: `/*! @name ${pkg.name} @version ${pkg.version} @license ${pkg.license} */`,
coverage: true
coverage: true,
minifierPlugin: 'uglify'
}, options || {});

Object.keys(ORDERED_DEFAULTS).forEach(function(key) {
Expand Down Expand Up @@ -221,6 +231,16 @@ const generateRollupConfig = function(options) {
return b;
};

const minPlugins = [];

if (settings.minifierPlugin) {
if (!settings.primedPlugins[settings.minifierPlugin]) {
throw new Error(`minifierPlugin ${settings.minifierPlugin} is not in primedPlugins`);
}

minPlugins.push(settings.primedPlugins[settings.minifierPlugin]);
}

/* all rollup builds by name. note only object values will be used */
const builds = {
test: makeBuild('test', {
Expand All @@ -239,7 +259,7 @@ const generateRollupConfig = function(options) {
name: settings.exportName,
file: `dist/${settings.distName}.min.js`,
format: 'umd',
plugins: [settings.primedPlugins.uglify]
plugins: minPlugins
// remove .min.js output if should change watch is true
}].filter((o) => !(MINJS_REGEX.test(o.file) && shouldChangeWatch(settings)))
}),
Expand Down
137 changes: 55 additions & 82 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-multi-entry": "^4.0.0",
"@rollup/plugin-node-resolve": "^9.0.0",
"@videojs/babel-config": "^0.1.1",
"@videojs/babel-config": "^0.2.0",
"rollup-plugin-istanbul": "^2.0.1",
"rollup-plugin-terser": "^7.0.2"
},
Expand Down