Skip to content

Commit

Permalink
build: fix postcss dist warning
Browse files Browse the repository at this point in the history
closes #419
  • Loading branch information
stasson committed Apr 29, 2018
1 parent 7d079e8 commit 424cac8
Showing 1 changed file with 107 additions and 99 deletions.
206 changes: 107 additions & 99 deletions rollup.config.js
@@ -1,17 +1,17 @@
import os from 'os';
import path from 'path';
import resolve from 'rollup-plugin-node-resolve';
import babel from 'rollup-plugin-babel';
import commonjs from 'rollup-plugin-commonjs';
import vue from 'rollup-plugin-vue';
import uglify from 'rollup-plugin-uglify';
import sass from 'rollup-plugin-sass';
import autoprefixer from 'autoprefixer';
import postcss from 'postcss';
import csso from 'postcss-csso';
import { minify } from 'uglify-es';
import pkg from './package.json';
import replace from 'rollup-plugin-replace';
import os from 'os'
import path from 'path'
import resolve from 'rollup-plugin-node-resolve'
import babel from 'rollup-plugin-babel'
import commonjs from 'rollup-plugin-commonjs'
import vue from 'rollup-plugin-vue'
import uglify from 'rollup-plugin-uglify'
import sass from 'rollup-plugin-sass'
import autoprefixer from 'autoprefixer'
import postcss from 'postcss'
import csso from 'postcss-csso'
import { minify } from 'uglify-es'
import pkg from './package.json'
import replace from 'rollup-plugin-replace'

const PLUGINS = [
'button',
Expand Down Expand Up @@ -40,8 +40,8 @@ const PLUGINS = [
'textfield',
'theme',
'toolbar',
'typography',
];
'typography'
]

const BANNER = `/**
* @module vue-mdc-adapter{{module}} {{version}}
Expand All @@ -55,7 +55,7 @@ const BANNER = `/**
`
.replace('{{version}}', pkg.version)
.replace('{{dependencies}}', JSON.stringify(pkg.dependencies))
.replace('{{peerDependencies}}', JSON.stringify(pkg.peerDependencies));
.replace('{{peerDependencies}}', JSON.stringify(pkg.peerDependencies))

const babelConfig = {
compact: false,
Expand All @@ -65,64 +65,72 @@ const babelConfig = {
// env preset https://github.com/babel/babel-preset-env
'env',
// let rollup take care of modules
{ modules: false },
],
{ modules: false }
]
],
plugins: [
'transform-object-assign',
'transform-object-rest-spread',
// let rollup bundle helpers once
// see https://github.com/rollup/rollup-plugin-babel#helpers
'external-helpers',
],
};
'external-helpers'
]
}

const capitalize = str => {
return str
.replace(/\b(\w)/g, function(_, x) {
return x.toUpperCase();
return x.toUpperCase()
})
.replace(/[_.-]/g, '');
};
.replace(/[_.-]/g, '')
}

function createUmdConfig(module, env, extract) {
const isPlugin = PLUGINS.includes(module);
const isProduction = env === `production`;
const isDevelopment = env === `development`;
const dist = isPlugin ? `dist/${module}/${module}` : 'dist/' + module;
const name = isPlugin ? 'VueMDC' + capitalize(module) : 'VueMDCAdapter';
const input = 'components/' + (isPlugin ? module + '/' : '') + 'entry.js';
const isPlugin = PLUGINS.includes(module)
const isProduction = env === `production`
const isDevelopment = env === `development`
const dist = isPlugin ? `dist/${module}/${module}` : 'dist/' + module
const name = isPlugin ? 'VueMDC' + capitalize(module) : 'VueMDCAdapter'
const input = 'components/' + (isPlugin ? module + '/' : '') + 'entry.js'

const banner = BANNER.replace('{{module}}', isPlugin ? module : '').replace(
'{{name}}',
name,
);
name
)

const postcssPlugins = isDevelopment
? [autoprefixer()]
: [autoprefixer(), csso()]

const postCssOptions = {
from: undefined
}

const sassConfig = {
include: ['**/*.css', '**/*.scss'],
options: { includePaths: ['node_modules'] },
processor: css =>
postcss(isDevelopment ? [autoprefixer()] : [autoprefixer(), csso()])
.process(css)
.then(result => result.css),
};
postcss(postcssPlugins)
.process(css, postCssOptions)
.then(result => result.css)
}

const output = {
file: dist + (isDevelopment ? `.js` : `.min.js`),
format: 'umd',
sourcemap: isDevelopment ? 'inline' : true,
name,
banner,
};
banner
}

if (extract) {
if (isProduction) {
sassConfig.output = dist + '.min.css';
sassConfig.output = dist + '.min.css'
} else {
sassConfig.output = dist + '.css';
sassConfig.output = dist + '.css'
}
} else {
sassConfig.insert = true;
sassConfig.insert = true
}

const config = {
Expand All @@ -136,73 +144,73 @@ function createUmdConfig(module, env, extract) {
babel(babelConfig),
commonjs(),
replace({
__VERSION__: pkg.version,
}),
__VERSION__: pkg.version
})
],
onwarn,
};
onwarn
}

if (isProduction) {
config.plugins.push(
uglify(
{
output: {
comments: function(node, comment) {
var text = comment.value;
var type = comment.type;
var text = comment.value
var type = comment.type
if (type == 'comment2') {
// multiline comment
return /@preserve|@license|@cc_on/i.test(text);
return /@preserve|@license|@cc_on/i.test(text)
}
},
},
}
}
},
minify,
),
);
minify
)
)
}
return config;
return config
}

function createEsmConfig(module) {
const isModule = PLUGINS.includes(module);
const dist = isModule ? `dist/${module}/index.js` : 'dist/index.js';
const input = 'components/' + (isModule ? module + '/' : '') + 'index.js';
const isModule = PLUGINS.includes(module)
const dist = isModule ? `dist/${module}/index.js` : 'dist/index.js'
const input = 'components/' + (isModule ? module + '/' : '') + 'index.js'
const banner = BANNER.replace('{{module}}', isModule ? module : '').replace(
'{{name}}',
'default',
);
'default'
)

let external = [];
let paths = {};
let outro = '';
let external = []
let paths = {}
let outro = ''

if (isModule) {
PLUGINS.forEach(folder => {
if (folder != module) {
let id = path.resolve('.', 'components', folder, 'index.js');
external.push(id);
paths[id] = `../${folder}`;
let id = path.resolve('.', 'components', folder, 'index.js')
external.push(id)
paths[id] = `../${folder}`
}
});
})
} else {
PLUGINS.forEach(folder => {
if (folder != module) {
let id = path.resolve('.', 'components', folder, 'index.js');
external.push(id);
paths[id] = `./${folder}`;
let id = path.resolve('.', 'components', folder, 'index.js')
external.push(id)
paths[id] = `./${folder}`
}
});
})

PLUGINS.forEach(folder => {
let exportName = 'VueMDC' + capitalize(folder);
outro += `export { ${exportName} }` + os.EOL;
});
let exportName = 'VueMDC' + capitalize(folder)
outro += `export { ${exportName} }` + os.EOL
})

outro += os.EOL;
outro += os.EOL
PLUGINS.forEach(folder => {
outro += `export * from './${folder}'` + os.EOL;
});
outro += `export * from './${folder}'` + os.EOL
})
}

const output = {
Expand All @@ -211,8 +219,8 @@ function createEsmConfig(module) {
sourcemap: true,
banner,
paths,
outro,
};
outro
}

const config = {
input,
Expand All @@ -224,42 +232,42 @@ function createEsmConfig(module) {
babel(babelConfig),
commonjs(),
replace({
__VERSION__: pkg.version,
}),
__VERSION__: pkg.version
})
],
onwarn,
};
return config;
onwarn
}
return config
}

const configs = [];
const configs = []

// ESM
PLUGINS.forEach(module => {
configs.push(createEsmConfig(module));
});
configs.push(createEsmConfig('index'));
configs.push(createEsmConfig(module))
})
configs.push(createEsmConfig('index'))

// UMD
PLUGINS.forEach(module => {
configs.push(createUmdConfig(module, 'development', true));
configs.push(createUmdConfig(module, 'production', true));
});
configs.push(createUmdConfig(module, 'development', true))
configs.push(createUmdConfig(module, 'production', true))
})

configs.push(createUmdConfig('vue-mdc-adapter', 'development', true));
configs.push(createUmdConfig('vue-mdc-adapter', 'production', true));
configs.push(createUmdConfig('vue-mdc-adapter.umd', 'development', false));
configs.push(createUmdConfig('vue-mdc-adapter.umd', 'production', false));
configs.push(createUmdConfig('vue-mdc-adapter', 'development', true))
configs.push(createUmdConfig('vue-mdc-adapter', 'production', true))
configs.push(createUmdConfig('vue-mdc-adapter.umd', 'development', false))
configs.push(createUmdConfig('vue-mdc-adapter.umd', 'production', false))

function onwarn(warning) {
// skip certain warnings
if (warning.code == 'NON_EXISTENT_EXPORT') {
if (warning.name == 'MDCIconToggleAdapter') return;
if (warning.name == 'MDCIconToggleAdapter') return
}

// console.warn everything else
console.log(warning);
console.warn(warning.message);
console.log(warning)
console.warn(warning.message)
}

export default configs;
export default configs

0 comments on commit 424cac8

Please sign in to comment.