2
0
mirror of https://github.com/tenrok/vue2-datepicker.git synced 2026-06-21 13:20:36 +03:00

refactor: 3.0

This commit is contained in:
mengxiong10
2019-11-10 17:47:30 +08:00
parent 72024440d7
commit 4875dc6b3d
165 changed files with 23248 additions and 21723 deletions
+52
View File
@@ -0,0 +1,52 @@
const path = require('path');
const fs = require('fs');
const libLocales = path.resolve(__dirname, '../../node_modules/date-format-parse/lib/locale');
const localLocalePath = path.resolve(__dirname, '../../src/locale');
const yearBeforeMonth = ['hu', 'ja', 'ko', 'lv', 'vi', 'zh-cn', 'zh-tw'];
const yearFormatMap = {
'zh-cn': 'YYYY年',
'zh-tw': 'YYYY年',
};
const getTemplate = locale => {
const formatLocale = locale.replace(/-(\w+)/, (m, p1) => p1.toLocaleUpperCase());
const yearFormat = yearFormatMap[locale] || 'YYYY';
const template = `
${locale === 'en' ? '' : "import DatePicker from 'vue2-datepicker';"}
import ${formatLocale} from 'date-format-parse/lib/locale/${locale}';
const lang = {
formatLocale: ${formatLocale},
yearFormat: '${yearFormat}',
monthFormat: 'MMM',
monthBeforeYear: ${yearBeforeMonth.indexOf(locale) === -1},
};
${locale === 'en' ? '' : `DatePicker.locale('${locale}', lang);`}
export default lang;
`;
return template.trim();
};
function generateLocales() {
fs.readdirSync(libLocales).forEach(filename => {
if (!/\.js$/.test(filename)) {
return;
}
const name = filename.replace(/\.js$/, '');
const data = getTemplate(name);
fs.writeFile(path.join(localLocalePath, filename), data, err => {
if (err) {
throw err;
}
});
});
}
generateLocales();
-48
View File
@@ -1,48 +0,0 @@
const path = require('path')
const VueLoaderPlugin = require('vue-loader/lib/plugin')
module.exports = {
resolve: {
extensions: ['.js', '.vue', '.json'],
alias: {
'@': path.join(__dirname, '..', 'src')
}
},
module: {
rules: [
{
test: /\.vue$/,
use: [
{
loader: 'vue-loader',
options: {
}
}
]
},
{
test:/\.scss$/,
use: ['vue-style-loader', 'css-loader', 'postcss-loader', 'sass-loader']
},
{
test: /\.js$/,
use: ['babel-loader'],
exclude: /node_modules/
},
{
test: /\.(png|jpg|gif|svg)$/,
use: [
{
loader: 'file-loader',
options: {
name: '[name].[ext]?[hash]'
}
}
]
}
]
},
plugins: [
new VueLoaderPlugin()
]
}
-13
View File
@@ -1,13 +0,0 @@
const merge = require('webpack-merge')
const devWebpackConfig = require('./webpack.dev.config.js')
const webpackConfig = merge(devWebpackConfig, {
devtool: 'source-map',
mode: 'production',
externals: {
'vue': 'Vue',
'@/index': 'DatePicker'
},
})
module.exports = webpackConfig
-50
View File
@@ -1,50 +0,0 @@
const path = require('path')
const merge = require('webpack-merge')
const baseWebpackConfig = require('./webpack.base.config.js')
const MiniCssExtractPlugin = require("mini-css-extract-plugin")
const OptimizeCSSPlugin = require('optimize-css-assets-webpack-plugin')
const webpackConfig = merge(baseWebpackConfig, {
mode: 'production',
entry: './src/index.js',
output: {
path: path.resolve(__dirname, '../lib'),
filename: 'index.js',
library: "DatePicker",
libraryTarget: "umd"
},
plugins: [
new OptimizeCSSPlugin({
cssProcessorOptions: { safe: true }
})
]
})
const webpackConfigExtractCss = merge(baseWebpackConfig, {
mode: 'production',
entry: './src/index.js',
output: {
path: path.resolve(__dirname, '../lib'),
filename: 'datepicker.js',
library: "DatePicker",
libraryTarget: "umd"
},
module: {
rules: [
{
test:/\.scss$/,
use: [ MiniCssExtractPlugin.loader, 'css-loader', 'postcss-loader', 'sass-loader']
},
]
},
plugins: [
new MiniCssExtractPlugin({
filename: 'datepicker.css'
}),
new OptimizeCSSPlugin({
cssProcessorOptions: { safe: true }
})
]
})
module.exports = [ webpackConfig, webpackConfigExtractCss]
-31
View File
@@ -1,31 +0,0 @@
const path = require('path')
const merge = require('webpack-merge')
const baseWebpackConfig = require('./webpack.base.config.js')
const VueLoaderPlugin = require('vue-loader/lib/plugin')
const webpackConfig = merge(baseWebpackConfig, {
mode: 'development',
entry: './demo/index.js',
output: {
path: path.resolve(__dirname, '../demo'),
filename: 'build.js'
},
externals: {
'vue': 'Vue'
},
devServer: {
historyApiFallback: {
index: './demo/index.html'
},
noInfo: true,
port: 9000,
host: '0.0.0.0'
},
performance: {
hints: false
},
devtool: 'source-map'
})
module.exports = webpackConfig