simplify build config (#638)

This commit is contained in:
neverland
2018-02-12 15:46:52 +08:00
committed by GitHub
parent 9673da4131
commit e1544fe919
13 changed files with 157 additions and 15758 deletions
+11 -9
View File
@@ -33,13 +33,11 @@ function compile(dir) {
// 移除 vant-css
if (file.indexOf('vant-css') !== -1) {
fs.removeSync(absolutePath);
}
// 遍历文件夹
else if (isDir(absolutePath)) {
// 遍历文件夹
} else if (isDir(absolutePath)) {
return compile(absolutePath);
}
// 编译 .vue 文件
else if (/\.vue$/.test(file)) {
// 编译 .vue 文件
} else if (/\.vue$/.test(file)) {
const source = fs.readFileSync(absolutePath, 'utf-8');
fs.removeSync(absolutePath);
@@ -49,9 +47,13 @@ function compile(dir) {
fs.outputFileSync(output, compiler(source, compilerOption).js);
} else if (/\.js$/.test(file)) {
babel.transformFile(absolutePath, compilerOption.babel, (err, { code }) => {
fs.outputFileSync(absolutePath, code);
});
babel.transformFile(
absolutePath,
compilerOption.babel,
(err, { code }) => {
fs.outputFileSync(absolutePath, code);
}
);
}
});
}
+4 -4
View File
@@ -13,8 +13,8 @@ const chalk = require('chalk');
require('shelljs/global');
// 1. lint
log('Starting', 'lint');
exec('npm run lint --silent');
log('Starting', 'lint');
exec('npm run lint --silent');
log('Finished', 'lint');
// 2. build entry
@@ -32,7 +32,7 @@ log('Starting', 'build:vant-css');
exec('npm run build:vant-css --silent');
log('Finished', 'build:vant-css');
// 5. build vant.js
// 5. build vant.js
log('Starting', 'build:vant');
exec('npm run build:vant --silent');
log('Finished', 'build:vant');
@@ -46,7 +46,7 @@ log('Finished', 'build:style-entries');
function log(status, action, breakLine) {
const now = new Date();
const clock = `${breakLine ? '\n' : ''}[${padZero(now.getHours())}:${padZero(now.getMinutes())}:${padZero(now.getSeconds())}]`;
console.log(`${chalk.gray(clock)} ${status} '${action ? chalk.cyan.bold(action ) : ''}'`);
console.log(`${chalk.gray(clock)} ${status} '${action ? chalk.cyan.bold(action) : ''}'`);
}
function padZero(num) {
-1
View File
@@ -6,7 +6,6 @@ const fs = require('fs-extra');
const path = require('path');
const components = require('./get-components')();
const dependencyTree = require('dependency-tree');
const SEP = path.sep;
components.forEach(componentName => {
+2 -2
View File
@@ -4,5 +4,5 @@ const path = require('path');
module.exports = function() {
const dirs = fs.readdirSync(path.resolve(__dirname, '../../packages'));
const excludes = ['index.js', 'vant-css', 'mixins', 'utils', '.DS_Store'];
return dirs.filter(dirName => excludes.indexOf(dirName) === -1)
}
return dirs.filter(dirName => excludes.indexOf(dirName) === -1);
};
+25 -46
View File
@@ -1,50 +1,29 @@
const webpack = require('webpack');
const config = require('./webpack.config.dev.js');
const isMinify = process.argv.indexOf('-p') !== -1;
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const isMinify = process.argv.indexOf('-p') !== -1;
config.entry = {
'vant': './packages/index.js'
};
config.output = {
filename: isMinify ? './lib/[name].min.js' : './lib/[name].js',
library: 'vant',
libraryTarget: 'umd',
umdNamedDefine: true
};
config.externals = {
vue: {
root: 'Vue',
commonjs: 'vue',
commonjs2: 'vue',
amd: 'vue'
}
};
config.plugins = [
new webpack.DefinePlugin({
'process.env.NODE_ENV': '"production"'
}),
new webpack.LoaderOptionsPlugin({
minimize: true,
debug: false,
options: {
vue: {
autoprefixer: false,
preserveWhitespace: false
}
module.exports = Object.assign({}, config, {
entry: {
'vant': './packages/index.js'
},
output: {
filename: isMinify ? './lib/[name].min.js' : './lib/[name].js',
library: 'vant',
libraryTarget: 'umd',
umdNamedDefine: true
},
externals: {
vue: {
root: 'Vue',
commonjs: 'vue',
commonjs2: 'vue',
amd: 'vue'
}
}),
new webpack.optimize.ModuleConcatenationPlugin()
];
// analyze bundle size if need
// if (isMinify) {
// config.plugins.push(new BundleAnalyzerPlugin());
// }
delete config.devtool;
module.exports = config;
},
plugins: [
new webpack.DefinePlugin({
'process.env.NODE_ENV': '"production"'
}),
new webpack.optimize.ModuleConcatenationPlugin()
]
});
-1
View File
@@ -90,7 +90,6 @@ module.exports = {
}
]
},
devtool: 'source-map',
plugins: [
new ProgressBarPlugin(),
new HtmlWebpackPlugin({
+1 -11
View File
@@ -11,22 +11,12 @@ module.exports = merge(devConfig, {
umdNamedDefine: true,
chunkFilename: 'async_[name].[chunkhash:8].js'
},
devtool: false,
plugins: [
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify(process.env.NODE_ENV)
}
}),
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false,
drop_console: true
},
output: {
comments: false
},
sourceMap: false
})
new webpack.optimize.UglifyJsPlugin()
]
});