-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
203c76e
commit 0aecbb1
Showing
10 changed files
with
1,062 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
current node | ||
last 2 versions and > 2% | ||
ie > 10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,165 @@ | ||
import commonjs from '@rollup/plugin-commonjs'; // Convert CommonJS modules to ES6 | ||
import vue from 'rollup-plugin-vue'; // Handle .vue SFC files | ||
import buble from '@rollup/plugin-buble'; // Transpile/polyfill with reasonable browser support | ||
export default { | ||
input: 'src/wrapper.js', // Path relative to package.json | ||
// rollup.config.js | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
import vue from 'rollup-plugin-vue'; | ||
import alias from '@rollup/plugin-alias'; | ||
import commonjs from '@rollup/plugin-commonjs'; | ||
import replace from '@rollup/plugin-replace'; | ||
import babel from 'rollup-plugin-babel'; | ||
import { terser } from 'rollup-plugin-terser'; | ||
import minimist from 'minimist'; | ||
import scss from 'rollup-plugin-scss'; // handles '.css' and '.scss' | ||
|
||
// Get browserslist config and remove ie from es build targets | ||
const esbrowserslist = fs | ||
.readFileSync('./.browserslistrc') | ||
.toString() | ||
.split('\n') | ||
.filter(entry => entry && entry.substring(0, 2) !== 'ie'); | ||
|
||
const argv = minimist(process.argv.slice(2)); | ||
|
||
const projectRoot = path.resolve(__dirname, '..'); | ||
|
||
const baseConfig = { | ||
input: 'src/entry.js', | ||
plugins: { | ||
preVue: [ | ||
alias({ | ||
resolve: ['.js', '.jsx', '.ts', '.tsx', '.vue'], | ||
entries: { | ||
'@': path.resolve(projectRoot, 'src') | ||
} | ||
}) | ||
], | ||
replace: { | ||
'process.env.NODE_ENV': JSON.stringify('production'), | ||
'process.env.ES_BUILD': JSON.stringify('false') | ||
}, | ||
vue: { | ||
css: true, | ||
template: { | ||
isProduction: true | ||
} | ||
}, | ||
babel: { | ||
exclude: 'node_modules/**', | ||
runtimeHelpers: true, | ||
extensions: ['.js', '.jsx', '.ts', '.tsx', '.vue'] | ||
} | ||
} | ||
}; | ||
|
||
// ESM/UMD/IIFE shared settings: externals | ||
// Refer to https://rollupjs.org/guide/en/#warning-treating-module-as-external-dependency | ||
const external = [ | ||
// list external dependencies, exactly the way it is written in the import statement. | ||
// eg. 'jquery' | ||
// 'vue' | ||
]; | ||
|
||
// UMD/IIFE shared settings: output.globals | ||
// Refer to https://rollupjs.org/guide/en#output-globals for details | ||
const globals = { | ||
// Provide global variable names to replace your external imports | ||
// eg. jquery: '$' | ||
// vue: 'Vue' | ||
}; | ||
|
||
// Customize configs for individual targets | ||
const buildFormats = []; | ||
if (!argv.format || argv.format === 'es') { | ||
const esConfig = { | ||
...baseConfig, | ||
external, | ||
output: { | ||
name: 'Eplainer', | ||
exports: 'named', | ||
file: 'dist/vue-png-explainer.esm.js', | ||
format: 'esm', | ||
exports: 'named' | ||
}, | ||
plugins: [ | ||
commonjs(), | ||
vue({ | ||
css: true, // Dynamically inject css as a <style> tag | ||
compileTemplate: true, // Explicitly convert template to render function | ||
}), | ||
buble(), // Transpile to ES5 | ||
], | ||
}; | ||
replace({ | ||
...baseConfig.plugins.replace, | ||
'process.env.ES_BUILD': JSON.stringify('true') | ||
}), | ||
...baseConfig.plugins.preVue, | ||
vue(baseConfig.plugins.vue), | ||
babel({ | ||
...baseConfig.plugins.babel, | ||
presets: [ | ||
[ | ||
'@babel/preset-env', | ||
{ | ||
targets: esbrowserslist | ||
} | ||
] | ||
] | ||
}), | ||
commonjs(), | ||
scss() | ||
] | ||
}; | ||
buildFormats.push(esConfig); | ||
} | ||
|
||
if (!argv.format || argv.format === 'cjs') { | ||
const umdConfig = { | ||
...baseConfig, | ||
external, | ||
output: { | ||
compact: true, | ||
file: 'dist/vue-png-explainer.ssr.js', | ||
format: 'cjs', | ||
name: 'DiscoComponents', | ||
exports: 'named', | ||
globals | ||
}, | ||
plugins: [ | ||
replace(baseConfig.plugins.replace), | ||
...baseConfig.plugins.preVue, | ||
vue({ | ||
...baseConfig.plugins.vue, | ||
template: { | ||
...baseConfig.plugins.vue.template, | ||
optimizeSSR: true | ||
} | ||
}), | ||
babel(baseConfig.plugins.babel), | ||
commonjs(), | ||
scss() | ||
] | ||
}; | ||
buildFormats.push(umdConfig); | ||
} | ||
|
||
if (!argv.format || argv.format === 'iife') { | ||
const unpkgConfig = { | ||
...baseConfig, | ||
external, | ||
output: { | ||
compact: true, | ||
file: 'dist/vue-png-explainer.min.js', | ||
format: 'iife', | ||
name: 'DiscoComponents', | ||
exports: 'named', | ||
globals | ||
}, | ||
plugins: [ | ||
replace(baseConfig.plugins.replace), | ||
...baseConfig.plugins.preVue, | ||
vue(baseConfig.plugins.vue), | ||
babel(baseConfig.plugins.babel), | ||
commonjs(), | ||
terser({ | ||
output: { | ||
ecma: 5 | ||
} | ||
}), | ||
scss() | ||
] | ||
}; | ||
buildFormats.push(unpkgConfig); | ||
} | ||
|
||
// Export config | ||
export default buildFormats; |
Oops, something went wrong.