Skip to content

Commit

Permalink
Update rollup configs, dependencies, replace uglify with terser
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Dodge committed Mar 6, 2019
1 parent f3d7382 commit 4b34ee3
Show file tree
Hide file tree
Showing 5 changed files with 194 additions and 49 deletions.
13 changes: 12 additions & 1 deletion CHANGELOG.md
Expand Up @@ -7,9 +7,20 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
## [Unreleased]

### TODO
- Refactor rollup configs - allow per-compile options
- Add *browser* property to library-mode package.json for SSR usage

## [1.1.1] - 2019-03-06

### Changed
- Drop 'uglify-es' for 'terser' - uglify-es no longer maintained
- Refactor rollup configs with per-compile options
- Update template dependencies
- vue 2.6.8
- vue-template-compiler 2.6.8
- rollup 1.4.1
- rollup-plugin-vue 4.7.2
- rollup-plugin-commonjs 9.2.1

## [1.1.0] - 2019-01-31

### Changed
Expand Down
97 changes: 82 additions & 15 deletions templates/library/build/rollup.config.js
Expand Up @@ -8,18 +8,8 @@ import minimist from 'minimist';

const argv = minimist(process.argv.slice(2));

const config = {
const baseConfig = {
input: 'src/entry.js',
output: {
name: '<%-componentNamePascal%>',
exports: 'named',
globals: {
// When creating an iife or umd bundle, you will need to provide global variable names to replace your external imports
}
},
external: [
// list of the names of external dependencies, exactly the way it is written in the import statement.
],
plugins: [
replace({
'process.env.NODE_ENV': JSON.stringify('production'),
Expand All @@ -36,9 +26,86 @@ const config = {
],
};

// Only minify browser (iife) version
if (argv.format === 'iife') {
config.plugins.push(terser());
// UMD/IIFE shared settings: externals and output.globals
// Refer to https://rollupjs.org/guide/en#output-globals for details
const external = [
// list external dependencies, exactly the way it is written in the import statement.
// eg. 'jquery'
];
const globals = {
// Provide global variable names to replace your external imports
// eg. jquery: '$'
};

// Customize configs for individual targets
const buildFormats = [];
if (!argv.format || argv.format === 'es') {
const esConfig = {
...baseConfig,
output: {
file: 'dist/<%-componentName%>.esm.js',
format: 'esm',
exports: 'named',
},
plugins: [
...baseConfig.plugins,
terser({
output: {
ecma: 6,
},
}),
],
};
buildFormats.push(esConfig);
}

if (!argv.format || argv.format === 'umd') {
const umdConfig = {
...baseConfig,
external,
output: {
compact: true,
file: 'dist/<%-componentName%>.umd.js',
format: 'umd',
name: '<%-componentNamePascal%>',
exports: 'named',
globals,
},
plugins: [
...baseConfig.plugins,
terser({
output: {
ecma: 6,
},
}),
],
};
buildFormats.push(umdConfig);
}

if (!argv.format || argv.format === 'iife') {
const unpkgConfig = {
...baseConfig,
external,
output: {
compact: true,
file: 'dist/<%-componentName%>.min.js',
format: 'iife',
name: '<%-componentNamePascal%>',
exports: 'named',
globals,
},
plugins: [
...baseConfig.plugins,
terser({
output: {
ecma: 5,
},
}),
],
};
buildFormats.push(unpkgConfig);
}

export default config;
// Export config
export default buildFormats;
18 changes: 9 additions & 9 deletions templates/library/library-package.json
Expand Up @@ -14,10 +14,10 @@
],

"scripts": {
"build": "npm run build:unpkg & npm run build:es & npm run build:umd",
"build:umd": "cross-env NODE_ENV=production rollup --config build/rollup.config.js --format umd --file dist/<%-componentName%>.umd.js",
"build:es": "cross-env NODE_ENV=production rollup --config build/rollup.config.js --format es --file dist/<%-componentName%>.esm.js",
"build:unpkg": "cross-env NODE_ENV=production rollup --config build/rollup.config.js --format iife --file dist/<%-componentName%>.min.js"
"build": "cross-env NODE_ENV=production rollup --config build/rollup.config.js",
"build:umd": "cross-env NODE_ENV=production rollup --config build/rollup.config.js --format umd",
"build:es": "cross-env NODE_ENV=production rollup --config build/rollup.config.js --format es",
"build:unpkg": "cross-env NODE_ENV=production rollup --config build/rollup.config.js --format iife"
},

"dependencies": {
Expand All @@ -26,13 +26,13 @@
"devDependencies": {
"cross-env": "^5.2.0",
"minimist": "^1.2.0",
"rollup": "^1.1.2",
"rollup": "^1.4.1",
"rollup-plugin-buble": "^0.19.6",
"rollup-plugin-commonjs": "^9.2.0",
"rollup-plugin-commonjs": "^9.2.1",
"rollup-plugin-replace": "^2.1.0",
"rollup-plugin-terser": "^4.0.4",
"rollup-plugin-vue": "^4.6.2",
"vue": "^2.5.22",
"vue-template-compiler": "^2.5.22"
"rollup-plugin-vue": "^4.7.2",
"vue": "^2.6.8",
"vue-template-compiler": "^2.6.8"
}
}
97 changes: 82 additions & 15 deletions templates/single/build/rollup.config.js
Expand Up @@ -8,18 +8,8 @@ import minimist from 'minimist';

const argv = minimist(process.argv.slice(2));

const config = {
const baseConfig = {
input: 'src/entry.js',
output: {
name: '<%-componentNamePascal%>',
exports: 'named',
globals: {
// When creating an iife or umd bundle, you will need to provide global variable names to replace your external imports
}
},
external: [
// list of the names of external dependencies, exactly the way it is written in the import statement.
],
plugins: [
replace({
'process.env.NODE_ENV': JSON.stringify('production'),
Expand All @@ -36,9 +26,86 @@ const config = {
],
};

// Only minify browser (iife) version
if (argv.format === 'iife') {
config.plugins.push(terser());
// UMD/IIFE shared settings: externals and output.globals
// Refer to https://rollupjs.org/guide/en#output-globals for details
const external = [
// list external dependencies, exactly the way it is written in the import statement.
// eg. 'jquery'
];
const globals = {
// Provide global variable names to replace your external imports
// eg. jquery: '$'
};

// Customize configs for individual targets
const buildFormats = [];
if (!argv.format || argv.format === 'es') {
const esConfig = {
...baseConfig,
output: {
file: 'dist/<%-componentName%>.esm.js',
format: 'esm',
exports: 'named',
},
plugins: [
...baseConfig.plugins,
terser({
output: {
ecma: 6,
},
}),
],
};
buildFormats.push(esConfig);
}

if (!argv.format || argv.format === 'umd') {
const umdConfig = {
...baseConfig,
external,
output: {
compact: true,
file: 'dist/<%-componentName%>.umd.js',
format: 'umd',
name: '<%-componentNamePascal%>',
exports: 'named',
globals,
},
plugins: [
...baseConfig.plugins,
terser({
output: {
ecma: 6,
},
}),
],
};
buildFormats.push(umdConfig);
}

if (!argv.format || argv.format === 'iife') {
const unpkgConfig = {
...baseConfig,
external,
output: {
compact: true,
file: 'dist/<%-componentName%>.min.js',
format: 'iife',
name: '<%-componentNamePascal%>',
exports: 'named',
globals,
},
plugins: [
...baseConfig.plugins,
terser({
output: {
ecma: 5,
},
}),
],
};
buildFormats.push(unpkgConfig);
}

export default config;
// Export config
export default buildFormats;
18 changes: 9 additions & 9 deletions templates/single/single-package.json
Expand Up @@ -16,10 +16,10 @@
],

"scripts": {
"build": "npm run build:unpkg & npm run build:es & npm run build:umd",
"build:umd": "cross-env NODE_ENV=production rollup --config build/rollup.config.js --format umd --file dist/<%-componentName%>.umd.js",
"build:es": "cross-env NODE_ENV=production rollup --config build/rollup.config.js --format es --file dist/<%-componentName%>.esm.js",
"build:unpkg": "cross-env NODE_ENV=production rollup --config build/rollup.config.js --format iife --file dist/<%-componentName%>.min.js"
"build": "cross-env NODE_ENV=production rollup --config build/rollup.config.js",
"build:umd": "cross-env NODE_ENV=production rollup --config build/rollup.config.js --format umd",
"build:es": "cross-env NODE_ENV=production rollup --config build/rollup.config.js --format es",
"build:unpkg": "cross-env NODE_ENV=production rollup --config build/rollup.config.js --format iife"
},

"dependencies": {
Expand All @@ -28,13 +28,13 @@
"devDependencies": {
"cross-env": "^5.2.0",
"minimist": "^1.2.0",
"rollup": "^1.1.2",
"rollup": "^1.4.1",
"rollup-plugin-buble": "^0.19.6",
"rollup-plugin-commonjs": "^9.2.0",
"rollup-plugin-commonjs": "^9.2.1",
"rollup-plugin-replace": "^2.1.0",
"rollup-plugin-terser": "^4.0.4",
"rollup-plugin-vue": "^4.6.2",
"vue": "^2.5.22",
"vue-template-compiler": "^2.5.22"
"rollup-plugin-vue": "^4.7.2",
"vue": "^2.6.8",
"vue-template-compiler": "^2.6.8"
}
}

0 comments on commit 4b34ee3

Please sign in to comment.