-
Notifications
You must be signed in to change notification settings - Fork 785
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: improve build; check output for ES2018 compatibility
Close #1024 # Conflicts: # packages/@interactjs/dev-tools/visualizer/plugin.ts # packages/@interactjs/multi-target/plugin.ts
- Loading branch information
1 parent
f56f1fa
commit 164ebe3
Showing
19 changed files
with
304 additions
and
667 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 |
---|---|---|
@@ -1,4 +1,2 @@ | ||
maintained node versions | ||
last 5 versions | ||
> 2% | ||
not dead | ||
defaults and fully supports es6-module | ||
node >= 16 |
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
This file was deleted.
Oops, something went wrong.
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,90 @@ | ||
/* eslint-disable import/no-extraneous-dependencies */ | ||
const { resolve } = require('path') | ||
|
||
const babel = require('@rollup/plugin-babel') | ||
const commonjs = require('@rollup/plugin-commonjs') | ||
const nodeResolve = require('@rollup/plugin-node-resolve') | ||
const replace = require('@rollup/plugin-replace') | ||
const terser = require('@rollup/plugin-terser') | ||
const { defineConfig } = require('rollup') | ||
|
||
const headers = require('./scripts/headers') | ||
const { extendBabelOptions, getModuleDirectories, isPro } = require('./scripts/utils') | ||
|
||
const globals = { | ||
react: 'React', | ||
vue: 'Vue', | ||
} | ||
const external = Object.keys(globals) | ||
const INPUT_EXTENSIONS = ['.ts', '.tsx', '.vue'] | ||
|
||
module.exports = defineConfig(async () => { | ||
const variations = [ | ||
{ env: { NODE_ENV: 'development' }, ext: '.js', minify: isPro }, | ||
{ env: { NODE_ENV: 'production' }, ext: '.min.js', minify: true }, | ||
] | ||
|
||
return variations.map(({ minify, ext, env }) => { | ||
const babelConfig = extendBabelOptions({ | ||
babelrc: false, | ||
configFile: false, | ||
browserslistConfigFile: false, | ||
targets: { ie: 9 }, | ||
babelHelpers: 'bundled', | ||
skipPreflightCheck: true, | ||
extensions: INPUT_EXTENSIONS, | ||
plugins: [[require.resolve('@babel/plugin-transform-runtime'), { helpers: false, regenerator: true }]], | ||
}) | ||
|
||
return defineConfig({ | ||
input: resolve(__dirname, 'packages', 'interactjs', 'index.ts'), | ||
external, | ||
plugins: [ | ||
nodeResolve({ | ||
modulePaths: getModuleDirectories(), | ||
extensions: INPUT_EXTENSIONS, | ||
}), | ||
commonjs({ include: '**/node_modules/{rebound,symbol-tree}/**' }), | ||
babel(babelConfig), | ||
replace({ | ||
preventAssignment: true, | ||
values: Object.entries({ | ||
npm_package_version: process.env.npm_package_version, | ||
IJS_BUNDLE: '1', | ||
...env, | ||
}).reduce((acc, [key, value]) => { | ||
acc[`process.env.${key}`] = JSON.stringify(value) | ||
return acc | ||
}, {}), | ||
}), | ||
minify && | ||
terser({ | ||
module: false, | ||
mangle: true, | ||
compress: { | ||
ecma: 5, | ||
unsafe: true, | ||
unsafe_Function: true, | ||
unsafe_arrows: false, | ||
unsafe_methods: true, | ||
}, | ||
format: { | ||
preamble: headers?.min, | ||
}, | ||
}), | ||
], | ||
context: 'window', | ||
moduleContext: 'window', | ||
output: { | ||
file: resolve(__dirname, 'packages', 'interactjs', 'dist', `interact${ext}`), | ||
format: 'umd', | ||
name: 'interact', | ||
banner: minify ? headers.min : headers.raw, | ||
minifyInternalExports: true, | ||
inlineDynamicImports: true, | ||
sourcemap: true, | ||
globals, | ||
}, | ||
}) | ||
}) | ||
}) |
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,165 @@ | ||
/* eslint-disable import/no-extraneous-dependencies */ | ||
const { resolve, basename, dirname, relative, extname } = require('path') | ||
const { promisify } = require('util') | ||
|
||
const { transformAsync } = require('@babel/core') | ||
const babel = require('@rollup/plugin-babel') | ||
const commonjs = require('@rollup/plugin-commonjs') | ||
const nodeResolve = require('@rollup/plugin-node-resolve') | ||
const replace = require('@rollup/plugin-replace') | ||
const terser = require('@rollup/plugin-terser') | ||
const { defineConfig } = require('rollup') | ||
const glob = promisify(require('glob')) | ||
|
||
const headers = require('./scripts/headers') | ||
const { | ||
getPackages, | ||
sourcesIgnoreGlobs, | ||
extendBabelOptions, | ||
getEsnextBabelOptions, | ||
getModuleDirectories, | ||
isPro, | ||
} = require('./scripts/utils') | ||
|
||
const BUNDLED_DEPS = ['rebound', 'symbol-tree'] | ||
const INPUT_EXTENSIONS = ['.ts', '.tsx', '.vue'] | ||
const moduleDirectory = getModuleDirectories() | ||
|
||
module.exports = defineConfig(async () => { | ||
const packageDirs = (await getPackages()).map((dir) => resolve(__dirname, dir)) | ||
return ( | ||
await Promise.all( | ||
packageDirs.map(async (packageDir) => { | ||
const packageName = `${basename(dirname(packageDir))}/${basename(packageDir)}` | ||
|
||
const external = (id_, importer) => { | ||
const id = id_.startsWith('.') ? resolve(dirname(importer), id_) : id_ | ||
|
||
// not external if it's a dependency that's intented to be bundled | ||
if (BUNDLED_DEPS.some((dep) => id === dep || id.includes(`/node_modules/${dep}/`))) return false | ||
|
||
// not external if the id is in the current package dir | ||
if ( | ||
[packageName, packageDir].some( | ||
(prefix) => | ||
id.startsWith(prefix) && (id.length === prefix.length || id.charAt(prefix.length) === '/'), | ||
) | ||
) | ||
return false | ||
|
||
return true | ||
} | ||
|
||
const entryFiles = await glob('**/*.{ts,tsx}', { | ||
cwd: packageDir, | ||
ignore: sourcesIgnoreGlobs, | ||
strict: false, | ||
nodir: true, | ||
absolute: true, | ||
}) | ||
const input = Object.fromEntries( | ||
entryFiles.map((file) => [ | ||
relative(packageDir, file.slice(0, file.length - extname(file).length)), | ||
file, | ||
]), | ||
) | ||
|
||
return [ | ||
// dev unminified | ||
{ env: { NODE_ENV: 'development' }, ext: '.js', minify: isPro }, | ||
// prod minified | ||
{ env: { NODE_ENV: 'production' }, ext: '.prod.js', minify: true }, | ||
].map(({ env, ext, minify }) => | ||
defineConfig({ | ||
external, | ||
input, | ||
plugins: [ | ||
commonjs({ include: '**/node_modules/{rebound,symbol-tree}/**' }), | ||
nodeResolve({ | ||
modulePaths: moduleDirectory, | ||
extensions: INPUT_EXTENSIONS, | ||
}), | ||
babel( | ||
extendBabelOptions( | ||
{ | ||
babelrc: false, | ||
configFile: false, | ||
babelHelpers: 'bundled', | ||
skipPreflightCheck: true, | ||
extensions: INPUT_EXTENSIONS, | ||
plugins: [ | ||
[ | ||
require.resolve('@babel/plugin-transform-runtime'), | ||
{ helpers: false, regenerator: false }, | ||
], | ||
], | ||
}, | ||
getEsnextBabelOptions(), | ||
), | ||
), | ||
replace({ | ||
preventAssignment: true, | ||
values: Object.entries({ | ||
npm_package_version: process.env.npm_package_version, | ||
IJS_BUNDLE: '', | ||
...env, | ||
}).reduce((acc, [key, value]) => { | ||
acc[`process.env.${key}`] = JSON.stringify(value) | ||
return acc | ||
}, {}), | ||
}), | ||
], | ||
context: 'window', | ||
moduleContext: 'window', | ||
preserveEntrySignatures: 'strict', | ||
output: [ | ||
{ | ||
dir: packageDir, | ||
entryFileNames: `[name]${ext}`, | ||
format: 'es', | ||
banner: minify ? headers?.min : headers?.raw, | ||
inlineDynamicImports: false, | ||
sourcemap: true, | ||
plugins: [ | ||
{ | ||
name: '@interactjs/_dev:output-transforms', | ||
async renderChunk(code, chunk, outputOptions) { | ||
return await transformAsync(code, { | ||
babelrc: false, | ||
configFile: false, | ||
inputSourceMap: chunk.map, | ||
filename: `${packageDir}/${chunk.fileName}`, | ||
plugins: [ | ||
[ | ||
require.resolve('./scripts/babel/relative-imports'), | ||
{ extension: ext, moduleDirectory }, | ||
], | ||
[require.resolve('@babel/plugin-transform-class-properties'), { loose: true }], | ||
], | ||
}) | ||
}, | ||
}, | ||
minify && | ||
terser({ | ||
module: false, | ||
mangle: true, | ||
compress: { | ||
ecma: '2019', | ||
unsafe: true, | ||
unsafe_Function: true, | ||
unsafe_arrows: false, | ||
unsafe_methods: true, | ||
}, | ||
format: { | ||
preamble: headers?.min, | ||
}, | ||
}), | ||
], | ||
}, | ||
], | ||
}), | ||
) | ||
}), | ||
) | ||
).flat() | ||
}) |
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
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
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
Oops, something went wrong.