fix: target ES6 for ESM bundles, fixes #526

This commit is contained in:
Harttle
2022-08-15 02:34:23 +08:00
committed by Harttle
parent e874b4060b
commit 905a6dd149
3 changed files with 13 additions and 12 deletions
+1 -1
View File
@@ -32,7 +32,7 @@
"@typescript-eslint/no-unused-vars": ["error", { "vars": "all", "args": "none", "ignoreRestSiblings": false }] "@typescript-eslint/no-unused-vars": ["error", { "vars": "all", "args": "none", "ignoreRestSiblings": false }]
}, },
"overrides": [{ "overrides": [{
"files": ["**/*.js", "*.js"], "files": ["**/*.js", "**/*.mjs"],
"rules": { "rules": {
"@typescript-eslint/no-var-requires": "off" "@typescript-eslint/no-var-requires": "off"
} }
+2 -2
View File
@@ -11,7 +11,7 @@
}, },
"types": "dist/liquid.d.ts", "types": "dist/liquid.d.ts",
"scripts": { "scripts": {
"lint": "eslint \"**/*.ts\" .", "lint": "eslint \"**/*.mjs\" \"**/*.ts\" .",
"check": "npm run build && npm test && npm run lint && npm run perf:diff", "check": "npm run build && npm test && npm run lint && npm run perf:diff",
"test": "nyc mocha \"test/**/*.ts\"", "test": "nyc mocha \"test/**/*.ts\"",
"test:e2e": "mocha \"test/e2e/**/*.ts\"", "test:e2e": "mocha \"test/e2e/**/*.ts\"",
@@ -20,7 +20,7 @@
"perf:engines": "cd benchmark && npm run engines", "perf:engines": "cd benchmark && npm run engines",
"postversion": "npm run build:dist", "postversion": "npm run build:dist",
"build": "npm run build:dist && npm run build:docs", "build": "npm run build:dist && npm run build:docs",
"build:dist": "rollup -c rollup.config.ts", "build:dist": "rollup -c rollup.config.mjs",
"build:docs": "bin/build-docs.sh" "build:docs": "bin/build-docs.sh"
}, },
"bin": { "bin": {
+10 -9
View File
@@ -1,9 +1,10 @@
import { uglify } from 'rollup-plugin-uglify' import { uglify } from 'rollup-plugin-uglify'
import pkg from './package.json'
import typescript from 'rollup-plugin-typescript2' import typescript from 'rollup-plugin-typescript2'
import replace from 'rollup-plugin-replace' import replace from 'rollup-plugin-replace'
import versionInjector from 'rollup-plugin-version-injector' import versionInjector from 'rollup-plugin-version-injector'
import { createRequire } from 'module'
const pkg = createRequire(import.meta.url)('./package.json')
const version = process.env.VERSION || pkg.version const version = process.env.VERSION || pkg.version
const sourcemap = true const sourcemap = true
const banner = `/* const banner = `/*
@@ -14,16 +15,16 @@ const banner = `/*
const treeshake = { const treeshake = {
propertyReadSideEffects: false propertyReadSideEffects: false
} }
const tsconfig = { const tsconfig = (target) => ({
tsconfigOverride: { tsconfigOverride: {
include: [ 'src' ], include: [ 'src' ],
exclude: [ 'test', 'benchmark' ], exclude: [ 'test', 'benchmark' ],
compilerOptions: { compilerOptions: {
target: 'es5', target,
module: 'ES2015' module: 'ES2015'
} }
} }
} })
const versionInjection = versionInjector({ const versionInjection = versionInjector({
injectInComments: false, injectInComments: false,
injectInTags: { injectInTags: {
@@ -60,7 +61,7 @@ const nodeCjs = {
banner banner
}], }],
external: ['path', 'fs'], external: ['path', 'fs'],
plugins: [versionInjection, typescript(tsconfig)], plugins: [versionInjection, typescript(tsconfig('es5'))],
treeshake, treeshake,
input input
} }
@@ -75,7 +76,7 @@ const nodeEsm = {
plugins: [ plugins: [
versionInjection, versionInjection,
replace(esmRequire), replace(esmRequire),
typescript(tsconfig) typescript(tsconfig('es6'))
], ],
treeshake, treeshake,
input input
@@ -92,7 +93,7 @@ const browserEsm = {
versionInjection, versionInjection,
replace(browserFS), replace(browserFS),
replace(browserStream), replace(browserStream),
typescript(tsconfig) typescript(tsconfig('es6'))
], ],
treeshake, treeshake,
input input
@@ -110,7 +111,7 @@ const browserUmd = {
versionInjection, versionInjection,
replace(browserFS), replace(browserFS),
replace(browserStream), replace(browserStream),
typescript(tsconfig) typescript(tsconfig('es5'))
], ],
treeshake, treeshake,
input input
@@ -128,7 +129,7 @@ const browserMin = {
versionInjection, versionInjection,
replace(browserFS), replace(browserFS),
replace(browserStream), replace(browserStream),
typescript(tsconfig), typescript(tsconfig('es5')),
uglify() uglify()
], ],
treeshake, treeshake,