Skip to content

Commit

Permalink
move config
Browse files Browse the repository at this point in the history
  • Loading branch information
myliang committed Mar 1, 2019
1 parent 0f9051b commit 94f1efe
Show file tree
Hide file tree
Showing 5 changed files with 164 additions and 0 deletions.
22 changes: 22 additions & 0 deletions build/locale_loader.js
@@ -0,0 +1,22 @@
const path = require('path');

function getLocaleCode(name, code) {
return `${code.replace('export default', 'const message =')}
if (window && window.x && window.x.spreadsheet) {
window.x.spreadsheet.$messages = window.x.spreadsheet.$messages || {};
window.x.spreadsheet.$messages['${name}'] = message;
}
export default message;
`;
}

module.exports = require('babel-loader').custom(babel => {
return {
result(result, { options }) {
// console.log('options:', options);
const lang = path.basename(options.filename, '.js');
result.code = getLocaleCode(lang, result.code);
return result;
},
};
});
52 changes: 52 additions & 0 deletions build/webpack.config.js
@@ -0,0 +1,52 @@
const path = require('path');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');

const resolve = dir => path.join(__dirname, '..', dir);

module.exports = {
entry: {
xspreadsheet: './src/index.js',
},
module: {
rules: [
{
test: /\.js$/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env'],
}
},
include: [resolve('src'), resolve('test')],
},
{
test: /\.css$/,
use: [
MiniCssExtractPlugin.loader,
'style-loader',
'css-loader',
],
},
{
test: /\.less$/,
use: [
MiniCssExtractPlugin.loader,
'css-loader',
'less-loader',
],
},
{
test: /\.(png|svg|jpg|gif)$/,
use: [
'file-loader',
],
},
{
test: /\.(woff|woff2|eot|ttf|otf)$/,
use: [
'file-loader',
],
},
],
},
};
31 changes: 31 additions & 0 deletions build/webpack.dev.js
@@ -0,0 +1,31 @@
const merge = require('webpack-merge');
const common = require('./webpack.config.js');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');

module.exports = merge(common, {
mode: 'development',
plugins: [
new CleanWebpackPlugin(['dist']),
// you should know that the HtmlWebpackPlugin by default will generate its own index.html
new HtmlWebpackPlugin({
template: './index.html',
title: 'x-spreadsheet',
}),
new MiniCssExtractPlugin({
// Options similar to the same options in webpackOptions.output
// both options are optional
filename: '[name].[contenthash].css',
// chunkFilename: devMode ? '[id].[hash].css' : '[id].css',
}),
],
output: {
filename: '[name].[contenthash].js',
},
devtool: 'inline-source-map',
devServer: {
host: '0.0.0.0',
contentBase: '../dist',
},
});
30 changes: 30 additions & 0 deletions build/webpack.locale.js
@@ -0,0 +1,30 @@
const path = require('path');
const fs = require('fs');

const localeFiles = fs.readdirSync(path.resolve(__dirname, '../src/locale'));
const entry = {};
localeFiles.forEach((file) => {
const name = file.split('.')[0];

if (name !== 'locale') {
entry[name] = `./src/locale/${file}`;
}
});

module.exports = {
entry,
output: {
filename: '[name].js',
path: path.resolve(__dirname, '../dist/locale'),
},
module: {
rules: [
{
test: /\.js$/,
loader: path.resolve(__dirname, 'locale_loader.js'),
}
]
},
plugins: [
],
};
29 changes: 29 additions & 0 deletions build/webpack.prod.js
@@ -0,0 +1,29 @@
const path = require('path');
const merge = require('webpack-merge');
const common = require('./webpack.config.js');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');

module.exports = merge(common, {
mode: 'production',
devtool: 'source-map',
plugins: [
new CleanWebpackPlugin(['dist']),
// you should know that the HtmlWebpackPlugin by default will generate its own index.html
new HtmlWebpackPlugin({
template: './index.html',
title: 'x-spreadsheet',
}),
new MiniCssExtractPlugin({
// Options similar to the same options in webpackOptions.output
// both options are optional
filename: '[name].css',
// chunkFilename: devMode ? '[id].[hash].css' : '[id].css',
}),
],
output: {
filename: '[name].js',
path: path.resolve(__dirname, '../dist'),
},
});

0 comments on commit 94f1efe

Please sign in to comment.