Skip to content

Commit

Permalink
update build system
Browse files Browse the repository at this point in the history
  • Loading branch information
kazupon committed Apr 21, 2020
1 parent f870f35 commit ed932b9
Show file tree
Hide file tree
Showing 3 changed files with 512 additions and 466 deletions.
15 changes: 8 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@
"Type: Documentation": ":pencil: Documentation"
}
},
"dependencies": {
"vue": "^3.0.0-beta.2"
},
"devDependencies": {
"@microsoft/api-documenter": "^7.7.17",
"@microsoft/api-extractor": "^7.7.12",
Expand Down Expand Up @@ -64,7 +61,8 @@
"shipjs": "^0.18.1",
"ts-jest": "^25.3.0",
"typescript": "^3.8.3",
"typescript-eslint-language-service": "^2.0.3"
"typescript-eslint-language-service": "^2.0.3",
"vue": "^3.0.0-beta.2"
},
"engines": {
"node": ">= 10"
Expand All @@ -86,6 +84,9 @@
"license": "MIT",
"main": "dist/vue-i18n.cjs.js",
"module": "dist/vue-i18n.esm-bundler.js",
"peerDependencies": {
"vue": "^3.0.0-beta.2"
},
"repository": {
"type": "git",
"url": "git+https://github.com/intlify/vue-i18n-next.git"
Expand All @@ -99,15 +100,15 @@
"clean:cache": "rm -rf ./node_modules/.rts2_cache",
"clean:coverage": "rm -rf ./coverage",
"clean:dist": "rm -rf ./dist/**",
"clean:type": "rm -rf ./types/** ./temp ./dist/vue-i18n.d.ts",
"clean:docs": "rm -rf ./docs",
"clean:type": "rm -rf ./types/** ./temp ./dist/vue-i18n.d.ts",
"coverage": "opener coverage/lcov-report/index.html",
"dev:e2e": "jest --runInBand --config ./jest.e2e.config.js",
"dev:docs": "yarn build:type && yarn docs:api",
"dev:e2e": "jest --runInBand --config ./jest.e2e.config.js",
"docs:api": "api-documenter markdown -i ./temp -o docs",
"fix": "yarn lint:fix && yarn format:fix",
"format": "prettier --config .prettierrc --ignore-path .prettierignore '**/*.{js,json,html}'",
"format:fix": "yarn format --write",
"fix": "yarn lint:fix && yarn format:fix",
"lint": "eslint ./src ./test ./e2e --ext .js,.ts",
"lint:fix": "yarn lint --fix",
"release:prepare": "shipjs prepare",
Expand Down
60 changes: 46 additions & 14 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@ const outputConfigs = {
file: pkg.module,
format: 'es'
},
'esm-browser': {
file: pkg.browser,
format: 'es'
},
cjs: {
file: pkg.main,
format: 'cjs'
},
global: {
file: pkg.unpkg,
format: 'iife'
},
esm: {
file: pkg.browser,
format: 'es'
}
}

Expand All @@ -48,7 +48,7 @@ packageFormats.forEach(format => {
if (format === 'cjs') {
packageConfigs.push(createProductionConfig(format))
}
if (format === 'global' || format === 'esm') {
if (format === 'global' || format === 'esm-browser') {
packageConfigs.push(createMinifiedConfig(format))
}
})
Expand All @@ -68,10 +68,10 @@ function createConfig(format, output, plugins = []) {

const isProductionBuild =
process.env.__DEV__ === 'false' || /\.prod\.js$/.test(output.file)
const isGlobalBuild = format === 'global'
// const isRawESMBuild = format === 'esm'
// const isNodeBuild = format === 'cjs'
const isBundlerESMBuild = /esm-bundler/.test(format)
const isBrowserESMBuild = /esm-browser/.test(format)
const isNodeBuild = format === 'cjs'
const isGlobalBuild = format === 'global'

if (isGlobalBuild) {
output.name = 'VueI18n'
Expand Down Expand Up @@ -100,9 +100,19 @@ function createConfig(format, output, plugins = []) {
// during a single build.
hasTSChecked = true

// const external =
// isGlobalBuild || isRawESMBuild ? [] : Object.keys(pkg.dependencies || {})
const external = Object.keys(pkg.dependencies)
/*
const external =
isGlobalBuild || isBrowserESMBuild
? []
: [
...Object.keys(pkg.dependencies || {}),
...Object.keys(pkg.peerDependencies || {})
]
*/
const external = [
...Object.keys(pkg.dependencies || {}),
...Object.keys(pkg.peerDependencies || {})
]
const nodePlugins = [resolve(), commonjs()]

return {
Expand All @@ -112,7 +122,14 @@ function createConfig(format, output, plugins = []) {
external,
plugins: [
tsPlugin,
createReplacePlugin(isProductionBuild, isBundlerESMBuild),
createReplacePlugin(
isProductionBuild,
isBundlerESMBuild,
isBrowserESMBuild,
isGlobalBuild || isBrowserESMBuild || isBundlerESMBuild,
isGlobalBuild,
isNodeBuild
),
...nodePlugins,
...plugins
],
Expand All @@ -125,14 +142,29 @@ function createConfig(format, output, plugins = []) {
}
}

function createReplacePlugin(isProduction, isBundlerESMBuild) {
function createReplacePlugin(
isProduction,
isBundlerESMBuild,
isBrowserESMBuild,
isBrowserBuild,
isGlobalBuild,
isNodeBuild
) {
const replacements = {
__VERSION__: `"${pkg.version}"`,
__DEV__: isBundlerESMBuild
? // preserve to be handled by bundlers
`(process.env.NODE_ENV !== 'production')`
: // hard coded dev/prod builds
!isProduction
!isProduction,
// this is only used during Vue's internal tests
__TEST__: false,
// If the build is expected to run directly in the browser (global / esm builds)
__BROWSER__: isBrowserBuild,
__GLOBAL__: isGlobalBuild,
__ESM_BUNDLER__: isBundlerESMBuild,
__ESM_BROWSER__: isBrowserESMBuild,
__NODE_JS__: isNodeBuild
}
Object.keys(replacements).forEach(key => {
if (key in process.env) {
Expand Down
Loading

0 comments on commit ed932b9

Please sign in to comment.