Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
164 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
}, | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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', | ||
], | ||
}, | ||
], | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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', | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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: [ | ||
], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'), | ||
}, | ||
}); |