Skip to content

Commit

Permalink
build: update rollup config
Browse files Browse the repository at this point in the history
  • Loading branch information
xxyan0205 committed Dec 13, 2018
1 parent 7b90510 commit 7f0ae0b
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 31 deletions.
6 changes: 1 addition & 5 deletions .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@
"plugins": [
"transform-object-rest-spread",
"syntax-dynamic-import",
"transform-vue-jsx",
["import", {
"libraryName": "mand-mobile",
"libraryDirectory": "components"
}]
"transform-vue-jsx"
],
"env": {
"test": {
Expand Down
20 changes: 10 additions & 10 deletions build/rollup/build-example.rollup.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const rollup = require('rollup')
const path = require('path')

const inputOptions = {
input: path.resolve(PROJECT_DIR, 'examples/main.indemand.js'),
input: path.resolve(PROJECT_DIR, 'examples/main.js'),
plugins: rollupPlugin,
}

Expand All @@ -14,15 +14,15 @@ const outputCommonjsOptions = {

function build() {
return rollup.rollup(inputOptions)
.then(bundle => {
return bundle.write(outputCommonjsOptions).then(() => {
console.info('build example succ')
})
})
.catch(err => {
console.info(err)
console.info('build error')
})
.then(bundle => {
return bundle.write(outputCommonjsOptions).then(() => {
console.info('build example succ')
})
})
.catch(err => {
console.info(err)
console.info('build error')
})
}

build()
21 changes: 16 additions & 5 deletions build/rollup/build-mand-mobile.rollup.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,27 @@
const rollup = require('rollup')
const path = require('path')
const chalk = require('chalk')
const {
LIB_DIR,
PROJECT_DIR,
rollupPlugin
} = require('./rollup-plugin-config')
const isSpecial = process.env.BUILD_TYPE === 'special'
// const isSpecial = process.env.BUILD_TYPE === 'special'

const inputOptions = {
input: path.resolve(PROJECT_DIR, 'components/index.js'),
external: ['vue'],
plugins: rollupPlugin
plugins: rollupPlugin,
onwarn (warning) {
// skip certain warnings
if (warning.code === 'UNUSED_EXTERNAL_IMPORT') {
return
}
// throw on others
if (warning.code === 'NON_EXISTENT_EXPORT') {
throw new Error(warning.message)
}
}
}

function build() {
Expand All @@ -21,20 +32,20 @@ function build() {
file: path.resolve(LIB_DIR, 'mand-mobile.esm.js'),
format: 'es',
}).then(() => {
console.info('Build ES Module')
console.log('\n' + chalk.green.bold('BUILD ') + chalk.bgGreen.bold('ES BUNDLE') + chalk.green.bold(' SUCCESS'))
}),
bundle.write({
file: path.resolve(LIB_DIR, 'mand-mobile.umd.js'),
format: 'umd',
name: 'mand-mobile'
}).then(() => {
console.info('Build UMD Module Success')
console.log('\n' + chalk.green.bold('BUILD ') + chalk.bgGreen.bold('UMD BUNDLE') + chalk.green.bold(' SUCCESS'))
})
])
})
.catch(err => {
console.info(err)
console.info('build error')
console.log('\n' + chalk.red.bold('BUILD ') + chalk.bgRed.bold('BUNDLE') + chalk.red.bold(' FAIL'))
})
}

Expand Down
11 changes: 9 additions & 2 deletions build/rollup/build-vw-responsive.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const postcss = require('postcss')
const px2vw = require('postcss-pixel-to-viewport')
const fs = require('fs')
const path = require('path')
const chalk = require('chalk')
const TARGET_LIB_BASE = 'lib'
const TARGET_VW_LIB_BASE = 'lib-vw'

Expand Down Expand Up @@ -54,8 +55,14 @@ function compilePxToVwAll() {

function main() {
copyLib()
.then(compilePxToVwAll)
.catch(e => console.info(e))
.then(compilePxToVwAll)
.then(() => {
console.log('\n' + chalk.green.bold('BUILD ') + chalk.bgYellow.bold('VM/VW') + chalk.green.bold(' SUCCESS'))
})
.catch(err => {
console.info(err)
console.log('\n' + chalk.red.bold('BUILD ') + chalk.bgRed.bold('VM/VW') + chalk.red.bold(' FAIL'))
})
}

main()
2 changes: 1 addition & 1 deletion build/rollup/dev-server.rollup.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const history = require('connect-history-api-fallback')
const port = 4000

const inputOptions = {
input: path.resolve(PROJECT_DIR, 'examples/main.indemand.js'),
input: path.resolve(PROJECT_DIR, 'examples/main.js'),
plugins: rollupPlugin,
}

Expand Down
14 changes: 9 additions & 5 deletions build/rollup/rollup-plugin-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,24 +70,28 @@ function conditionHelper(condition, plugins) {
return condition ? plugins : []
}

const rollupSvgAlias = {
'@examples/assets/images/bank-zs.svg': resolve('examples/assets/images/bank-zs.svg'),
'@examples/assets/images/tip-package.svg': resolve('examples/assets/images/tip-package.svg')
}
const rollupPlugin = [
// resolve
...(conditionHelper(!isDev, [
aliasPlugin({
resolve: ['.js', '/index.js', '.css', '.vue', '.svg'], // @TODO '/index.js' hack
resolve: ['.js', '.json', '/index.js', '.css', '.vue', '.svg'], // @TODO '/index.js' hack
'mand-mobile/components': resolve('components'),
'mand-mobile/lib': resolve('lib'),
'mand-mobile': resolve('lib/mand-mobile.esm.js'),
'@examples/assets/images/bank-zs.svg': resolve('examples/assets/images/bank-zs.svg')
...rollupSvgAlias
}),
])),
...(conditionHelper(isDev, [
aliasPlugin({
resolve: ['.js', '/index.js', '.css', '.vue', '.svg'], // @TODO '/index.js' hack
resolve: ['.js', '.json', '/index.js', '.css', '.vue', '.svg'], // @TODO '/index.js' hack
'mand-mobile/components': resolve('components'),
'mand-mobile/lib': resolve('lib'),
'mand-mobile': resolve('components'),
'@examples/assets/images/bank-zs.svg': resolve('examples/assets/images/bank-zs.svg')
...rollupSvgAlias
}),
])),
nodeResolvePlugin({
Expand All @@ -96,7 +100,7 @@ const rollupPlugin = [
...(conditionHelper(isTest, [
common({
exclude: ['components/_util/*.js'],
namedExports: { 'avoriaz': ['mount', 'shallow'] },
namedExports: { '@vue/test-utils': ['mount', 'shallow'] },
}),
glob(),
])),
Expand Down
9 changes: 6 additions & 3 deletions build/rollup/rollup-plugin-example-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,18 @@ function vueWarpper() {
const vue = vueWarpper()
// const css = cssWarpper()


const rollupSvgAlias = {
'@examples/assets/images/bank-zs.svg': resolve('examples/assets/images/bank-zs.svg'),
'@examples/assets/images/tip-package.svg': resolve('examples/assets/images/tip-package.svg')
}
const rollupPlugin = [
// resolve
aliasPlugin({
resolve: ['.js', '/index.js', '.css', '.vue', '.svg'], // @TODO '/index.js' hack
resolve: ['.js', '.json', '/index.js', '.css', '.vue', '.svg'], // @TODO '/index.js' hack
'mand-mobile/components': resolve('components'),
'mand-mobile/lib': resolve('lib'),
'mand-mobile': resolve('components'),
'@examples/assets/images/bank-zs.svg': resolve('examples/assets/images/bank-zs.svg')
...rollupSvgAlias
}),
nodeResolvePlugin({
extensions: [ '.js', '.json', '.vue' ],
Expand Down

0 comments on commit 7f0ae0b

Please sign in to comment.