update: more changes to bundle config...
This commit is contained in:
+11
-5
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@braks/revue-flow",
|
"name": "@braks/revue-flow",
|
||||||
"version": "0.0.20",
|
"version": "0.0.22",
|
||||||
"private": false,
|
"private": false,
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@@ -8,8 +8,11 @@
|
|||||||
},
|
},
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"author": "Burak Cakmakoglu",
|
"author": "Burak Cakmakoglu",
|
||||||
"main": "dist/revue-flow.es.js",
|
"main": "dist/revue-flow.cjs.js",
|
||||||
"module": "dist/revue-flow.es.js",
|
"browser": "dist/revue-flow.esm.js",
|
||||||
|
"unpkg": "dist/revue-flow.global.js",
|
||||||
|
"jsdelivr": "dist/revue-flow.global.js",
|
||||||
|
"module": "dist/revue-flow.esm-bundler.js",
|
||||||
"types": "dist/index.d.ts",
|
"types": "dist/index.d.ts",
|
||||||
"files": [
|
"files": [
|
||||||
"dist",
|
"dist",
|
||||||
@@ -17,11 +20,11 @@
|
|||||||
],
|
],
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite",
|
"dev": "vite",
|
||||||
"build": "vue-tsc --noEmit && vite build && yarn build:dist",
|
"build": "vue-tsc --noEmit && vite build",
|
||||||
"build:dist": "rollup -c --environment NODE_ENV:production",
|
"build:dist": "rollup -c --environment NODE_ENV:production",
|
||||||
"build:app": "vite build -c vite.config.app.ts",
|
"build:app": "vite build -c vite.config.app.ts",
|
||||||
"serve": "vite preview",
|
"serve": "vite preview",
|
||||||
"prepublishOnly": "yarn build",
|
"prepublishOnly": "yarn build:dist",
|
||||||
"test": "exit 0;",
|
"test": "exit 0;",
|
||||||
"lint:js": "eslint --ext \".js,.jsx,.ts,.tsx\" --fix --ignore-path .gitignore .",
|
"lint:js": "eslint --ext \".js,.jsx,.ts,.tsx\" --fix --ignore-path .gitignore .",
|
||||||
"lint": "yarn lint:js"
|
"lint": "yarn lint:js"
|
||||||
@@ -57,6 +60,7 @@
|
|||||||
"eslint-plugin-prettier": "^3.3.1",
|
"eslint-plugin-prettier": "^3.3.1",
|
||||||
"eslint-plugin-vue": "^7.12.1",
|
"eslint-plugin-vue": "^7.12.1",
|
||||||
"np": "^7.5.0",
|
"np": "^7.5.0",
|
||||||
|
"pascalcase": "^1.0.0",
|
||||||
"postcss": "^8.3.5",
|
"postcss": "^8.3.5",
|
||||||
"postcss-cli": "^8.3.1",
|
"postcss-cli": "^8.3.1",
|
||||||
"postcss-nested": "^5.0.5",
|
"postcss-nested": "^5.0.5",
|
||||||
@@ -66,7 +70,9 @@
|
|||||||
"rollup-plugin-livereload": "^2.0.0",
|
"rollup-plugin-livereload": "^2.0.0",
|
||||||
"rollup-plugin-postcss": "^4.0.0",
|
"rollup-plugin-postcss": "^4.0.0",
|
||||||
"rollup-plugin-serve": "^1.1.0",
|
"rollup-plugin-serve": "^1.1.0",
|
||||||
|
"rollup-plugin-terser": "^7.0.2",
|
||||||
"rollup-plugin-typescript2": "^0.30.0",
|
"rollup-plugin-typescript2": "^0.30.0",
|
||||||
|
"rollup-plugin-vue": "^6.0.0",
|
||||||
"typescript": "^4.3.5",
|
"typescript": "^4.3.5",
|
||||||
"vite": "^2.3.8",
|
"vite": "^2.3.8",
|
||||||
"vue": "^3.0.5",
|
"vue": "^3.0.5",
|
||||||
|
|||||||
+200
-53
@@ -1,66 +1,213 @@
|
|||||||
|
import path from 'path';
|
||||||
|
import ts from 'rollup-plugin-typescript2';
|
||||||
|
import replace from '@rollup/plugin-replace';
|
||||||
import resolve from '@rollup/plugin-node-resolve';
|
import resolve from '@rollup/plugin-node-resolve';
|
||||||
import commonjs from '@rollup/plugin-commonjs';
|
import commonjs from '@rollup/plugin-commonjs';
|
||||||
import babel from '@rollup/plugin-babel';
|
import pascalcase from 'pascalcase';
|
||||||
|
import pkg from './package.json';
|
||||||
import postcss from 'rollup-plugin-postcss';
|
import postcss from 'rollup-plugin-postcss';
|
||||||
import replace from '@rollup/plugin-replace';
|
import babel from '@rollup/plugin-babel';
|
||||||
import typescript from 'rollup-plugin-typescript2';
|
|
||||||
import { DEFAULT_EXTENSIONS as DEFAULT_BABEL_EXTENSIONS } from '@babel/core';
|
import { DEFAULT_EXTENSIONS as DEFAULT_BABEL_EXTENSIONS } from '@babel/core';
|
||||||
|
|
||||||
import pkg from './package.json';
|
const name = pkg.name;
|
||||||
|
|
||||||
const isProd = process.env.NODE_ENV === 'production';
|
function getAuthors(pkg) {
|
||||||
const isTesting = process.env.NODE_ENV === 'testing';
|
const { contributors, author } = pkg;
|
||||||
const processEnv = isProd || isTesting ? 'production' : 'development';
|
|
||||||
|
|
||||||
export const baseConfig = ({ injectCSS = true } = {}) => ({
|
const authors = new Set();
|
||||||
input: 'src/index.ts',
|
if (contributors && contributors)
|
||||||
external: ['vue', 'vue-demi', '@vue/composition-api', (id) => id.includes('@babel/runtime')],
|
contributors.forEach((contributor) => {
|
||||||
onwarn(warning, rollupWarn) {
|
authors.add(contributor.name);
|
||||||
if (warning.code !== 'CIRCULAR_DEPENDENCY') {
|
});
|
||||||
rollupWarn(warning);
|
if (author) authors.add(author.name);
|
||||||
}
|
|
||||||
|
return Array.from(authors).join(', ');
|
||||||
|
}
|
||||||
|
|
||||||
|
const banner = `/*!
|
||||||
|
* ${pkg.name} v${pkg.version}
|
||||||
|
* (c) ${new Date().getFullYear()} ${getAuthors(pkg)}
|
||||||
|
* @license MIT
|
||||||
|
*/`;
|
||||||
|
|
||||||
|
// ensure TS checks only once for each build
|
||||||
|
let hasTSChecked = false;
|
||||||
|
|
||||||
|
const outputConfigs = {
|
||||||
|
// each file name has the format: `dist/${name}.${format}.js`
|
||||||
|
// format being a key of this object
|
||||||
|
'esm-bundler': {
|
||||||
|
file: pkg.module,
|
||||||
|
format: 'es'
|
||||||
},
|
},
|
||||||
output: {
|
cjs: {
|
||||||
globals: {
|
file: pkg.main,
|
||||||
vue: 'Vue',
|
format: 'cjs'
|
||||||
'vue-demi': 'VueDemi'
|
|
||||||
},
|
|
||||||
dir: 'dist',
|
|
||||||
sourcemap: true,
|
|
||||||
exports: 'named'
|
|
||||||
},
|
},
|
||||||
plugins: [
|
'global-vue-3': {
|
||||||
replace({
|
file: pkg.unpkg.replace('2', '3'),
|
||||||
__ENV__: JSON.stringify(processEnv),
|
format: 'iife'
|
||||||
__REACT_FLOW_VERSION__: JSON.stringify(pkg.version),
|
},
|
||||||
preventAssignment: true
|
'global-vue-2': {
|
||||||
}),
|
file: pkg.unpkg,
|
||||||
postcss({
|
format: 'iife'
|
||||||
minimize: isProd,
|
},
|
||||||
inject: injectCSS
|
esm: {
|
||||||
}),
|
file: pkg.browser,
|
||||||
resolve(),
|
format: 'es'
|
||||||
typescript({
|
}
|
||||||
clean: true
|
};
|
||||||
}),
|
|
||||||
commonjs({
|
const allFormats = Object.keys(outputConfigs);
|
||||||
include: 'node_modules/**'
|
const packageFormats = allFormats;
|
||||||
}),
|
const packageConfigs = packageFormats.map((format) => createConfig(format, outputConfigs[format]));
|
||||||
babel({
|
|
||||||
extensions: [...DEFAULT_BABEL_EXTENSIONS, '.ts', '.tsx'],
|
// only add the production ready if we are bundling the options
|
||||||
exclude: 'node_modules/**',
|
packageFormats.forEach((format) => {
|
||||||
babelHelpers: 'inline'
|
if (format === 'cjs') {
|
||||||
})
|
packageConfigs.push(createProductionConfig(format));
|
||||||
]
|
} else if (format.startsWith('global')) {
|
||||||
|
packageConfigs.push(createMinifiedConfig(format));
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
export default isProd && !isTesting
|
export default packageConfigs;
|
||||||
? [
|
|
||||||
baseConfig(),
|
function createConfig(format, output, plugins = []) {
|
||||||
baseConfig({
|
if (!output) {
|
||||||
mainFile: 'dist/nocss/ReactFlow-nocss.js',
|
console.log(`invalid format: ${format}`);
|
||||||
moduleFile: 'dist/nocss/ReactFlow-nocss.esm.js',
|
process.exit(1);
|
||||||
injectCSS: false
|
}
|
||||||
|
output.exports = 'named';
|
||||||
|
output.sourcemap = !!process.env.SOURCE_MAP;
|
||||||
|
output.banner = banner;
|
||||||
|
output.externalLiveBindings = false;
|
||||||
|
output.globals = { vue: 'Vue', 'vue-demi': 'VueDemi' };
|
||||||
|
|
||||||
|
const isProductionBuild = /\.prod\.js$/.test(output.file);
|
||||||
|
const isGlobalBuild = format.startsWith('global');
|
||||||
|
const isRawESMBuild = format === 'esm';
|
||||||
|
const isNodeBuild = format === 'cjs';
|
||||||
|
const isBundlerESMBuild = /esm-bundler/.test(format);
|
||||||
|
|
||||||
|
if (isGlobalBuild) output.name = pascalcase(pkg.name);
|
||||||
|
|
||||||
|
const shouldEmitDeclarations = !hasTSChecked;
|
||||||
|
|
||||||
|
const tsPlugin = ts({
|
||||||
|
check: !hasTSChecked,
|
||||||
|
tsconfig: path.resolve(__dirname, 'tsconfig.json'),
|
||||||
|
cacheRoot: path.resolve(__dirname, 'node_modules/.rts2_cache'),
|
||||||
|
tsconfigOverride: {
|
||||||
|
compilerOptions: {
|
||||||
|
sourceMap: true,
|
||||||
|
declaration: shouldEmitDeclarations,
|
||||||
|
declarationMap: shouldEmitDeclarations
|
||||||
|
},
|
||||||
|
exclude: ['__tests__', 'test-dts']
|
||||||
|
}
|
||||||
|
});
|
||||||
|
// we only need to check TS and generate declarations once for each build.
|
||||||
|
// it also seems to run into weird issues when checking multiple times
|
||||||
|
// during a single build.
|
||||||
|
hasTSChecked = true;
|
||||||
|
|
||||||
|
const external = ['vue', 'vue-demi', '@vue/composition-api', (id) => id.includes('@babel/runtime')];
|
||||||
|
|
||||||
|
const nodePlugins = [resolve(), commonjs({ include: 'node_modules/**' })];
|
||||||
|
|
||||||
|
return {
|
||||||
|
input: 'src/index.ts',
|
||||||
|
// Global and Browser ESM builds inlines everything so that they can be
|
||||||
|
// used alone.
|
||||||
|
external,
|
||||||
|
plugins: [
|
||||||
|
tsPlugin,
|
||||||
|
createReplacePlugin(
|
||||||
|
isProductionBuild,
|
||||||
|
isBundlerESMBuild,
|
||||||
|
// isBrowserBuild?
|
||||||
|
isGlobalBuild || isRawESMBuild || isBundlerESMBuild,
|
||||||
|
isGlobalBuild,
|
||||||
|
isNodeBuild
|
||||||
|
),
|
||||||
|
...nodePlugins,
|
||||||
|
...plugins,
|
||||||
|
postcss({
|
||||||
|
minimize: true,
|
||||||
|
inject: true
|
||||||
|
}),
|
||||||
|
babel({
|
||||||
|
extensions: [...DEFAULT_BABEL_EXTENSIONS, '.ts', '.tsx'],
|
||||||
|
exclude: 'node_modules/**',
|
||||||
|
babelHelpers: 'inline'
|
||||||
|
})
|
||||||
|
],
|
||||||
|
output
|
||||||
|
// onwarn: (msg, warn) => {
|
||||||
|
// if (!/Circular/.test(msg)) {
|
||||||
|
// warn(msg)
|
||||||
|
// }
|
||||||
|
// },
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function createReplacePlugin(isProduction, isBundlerESMBuild, isBrowserBuild, isGlobalBuild, isNodeBuild) {
|
||||||
|
const replacements = {
|
||||||
|
__COMMIT__: `"${process.env.COMMIT}"`,
|
||||||
|
__VERSION__: `"${pkg.version}"`,
|
||||||
|
__DEV__: isBundlerESMBuild
|
||||||
|
? // preserve to be handled by bundlers
|
||||||
|
"(process.env.NODE_ENV !== 'production')"
|
||||||
|
: // hard coded dev/prod builds
|
||||||
|
!isProduction,
|
||||||
|
// this is only used during tests
|
||||||
|
__TEST__: isBundlerESMBuild ? "(process.env.NODE_ENV === 'test')" : false,
|
||||||
|
// If the build is expected to run directly in the browser (global / esm builds)
|
||||||
|
__BROWSER__: isBrowserBuild,
|
||||||
|
// is targeting bundlers?
|
||||||
|
__BUNDLER__: isBundlerESMBuild,
|
||||||
|
__GLOBAL__: isGlobalBuild,
|
||||||
|
// is targeting Node (SSR)?
|
||||||
|
__NODE_JS__: isNodeBuild,
|
||||||
|
__ENV__: JSON.stringify(process.env.NODE_ENV),
|
||||||
|
__REACT_FLOW_VERSION__: JSON.stringify(pkg.version),
|
||||||
|
preventAssignment: true
|
||||||
|
};
|
||||||
|
// allow inline overrides like
|
||||||
|
//__RUNTIME_COMPILE__=true yarn build
|
||||||
|
Object.keys(replacements).forEach((key) => {
|
||||||
|
if (key in process.env) {
|
||||||
|
replacements[key] = process.env[key];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return replace(replacements);
|
||||||
|
}
|
||||||
|
|
||||||
|
function createProductionConfig(format) {
|
||||||
|
return createConfig(format, {
|
||||||
|
file: `dist/${name}.${format}.prod.js`,
|
||||||
|
format: outputConfigs[format].format
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function createMinifiedConfig(format) {
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||||
|
const { terser } = require('rollup-plugin-terser');
|
||||||
|
return createConfig(
|
||||||
|
format,
|
||||||
|
{
|
||||||
|
file: `dist/${name}.${format}.prod.js`,
|
||||||
|
format: outputConfigs[format].format
|
||||||
|
},
|
||||||
|
[
|
||||||
|
terser({
|
||||||
|
module: /^esm/.test(format),
|
||||||
|
compress: {
|
||||||
|
ecma: 2015,
|
||||||
|
pure_getters: true
|
||||||
|
}
|
||||||
})
|
})
|
||||||
]
|
]
|
||||||
: baseConfig();
|
);
|
||||||
|
}
|
||||||
|
|||||||
+1
-9
@@ -12,14 +12,9 @@ export default defineConfig({
|
|||||||
},
|
},
|
||||||
sourcemap: true,
|
sourcemap: true,
|
||||||
rollupOptions: {
|
rollupOptions: {
|
||||||
// make sure to externalize deps that shouldn't be bundled
|
external: ['vue-demi'],
|
||||||
// into your library
|
|
||||||
external: ['vue', 'vue-demi', '@vue/composition-api'],
|
|
||||||
output: {
|
output: {
|
||||||
// Provide global variables to use in the UMD build
|
|
||||||
// for externalized deps
|
|
||||||
globals: {
|
globals: {
|
||||||
vue: 'Vue',
|
|
||||||
'vue-demi': 'VueDemi'
|
'vue-demi': 'VueDemi'
|
||||||
},
|
},
|
||||||
dir: 'dist',
|
dir: 'dist',
|
||||||
@@ -33,9 +28,6 @@ export default defineConfig({
|
|||||||
},
|
},
|
||||||
polyfillDynamicImport: true
|
polyfillDynamicImport: true
|
||||||
},
|
},
|
||||||
optimizeDeps: {
|
|
||||||
exclude: ['vue-demi']
|
|
||||||
},
|
|
||||||
plugins: [
|
plugins: [
|
||||||
vue(),
|
vue(),
|
||||||
vueJsx({
|
vueJsx({
|
||||||
|
|||||||
Reference in New Issue
Block a user