Skip to content

Commit 43b439a

Browse files
add mahal example
1 parent 628f62b commit 43b439a

File tree

23 files changed

+6937
-0
lines changed

23 files changed

+6937
-0
lines changed

mahal/.babelrc

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"presets": [
3+
[
4+
"@babel/preset-env",
5+
{
6+
"targets": {
7+
"node": "6.10"
8+
}
9+
}
10+
]
11+
],
12+
"plugins": [
13+
[
14+
"@babel/plugin-proposal-decorators",
15+
{
16+
"legacy": true
17+
}
18+
],
19+
"babel-plugin-parameter-decorator-custom"
20+
]
21+
}

mahal/.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
node_modules
2+
bin
3+
dist
4+
build
5+
logs

mahal/assets/img/mahal-logo.png

13.1 KB
Loading

mahal/config/env/development.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
apiUrl: "/"
3+
}

mahal/config/env/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
if (process.env.NODE_ENV == 'production') {
2+
module.exports = require('./production.js');
3+
}
4+
else {
5+
module.exports = require('./development.js');
6+
}

mahal/config/env/production.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
apiUrl: "/"
3+
}

mahal/config/lang/mahal.config.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
declare module "*.mahal" {
2+
// import Vue from "vue";
3+
// export default Vue;
4+
const value: any; // Add better type definitions here if desired.
5+
export default value;
6+
}
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
const path = require('path');
2+
const MahalPlugin = require('mahal-webpack-loader/lib/plugin');
3+
const HtmlWebPackPlugin = require('html-webpack-plugin');
4+
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
5+
const CopyPlugin = require('copy-webpack-plugin');
6+
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
7+
const webpack = require('webpack');
8+
9+
const rootFolder = path.join(__dirname, '../../');
10+
11+
const isEnvProduction = process.env.NODE_ENV === "production"
12+
13+
module.exports = {
14+
entry: './src/index.js',
15+
devtool: 'source-map',
16+
mode: process.env.NODE_ENV || "development",
17+
module: {
18+
rules: [
19+
{
20+
test: /\.mahal?$/,
21+
// loader: 'mahal-webpack-loader',
22+
use: {
23+
loader: require.resolve('mahal-webpack-loader')
24+
},
25+
exclude: /node_modules/
26+
},
27+
{
28+
test: /\.js|.jsx?$/,
29+
exclude: /(node_modules|bower_components)/,
30+
use: {
31+
loader: 'babel-loader'
32+
}
33+
},
34+
{
35+
test: /\.css?$/,
36+
use: [
37+
{
38+
loader: MiniCssExtractPlugin.loader,
39+
options: {
40+
esModule: false,
41+
},
42+
},
43+
'css-loader'
44+
],
45+
},
46+
{
47+
test: /\.s[ac]ss$/i,
48+
use: [
49+
// Creates `style` nodes from JS strings
50+
// "style-loader",
51+
{
52+
loader: MiniCssExtractPlugin.loader,
53+
options: {
54+
esModule: false,
55+
},
56+
},
57+
// Translates CSS into CommonJS
58+
"css-loader",
59+
// Compiles Sass to CSS
60+
"sass-loader",
61+
],
62+
},
63+
// Images
64+
{
65+
test: /\.(?:ico|gif|png|jpg|jpeg)$/i,
66+
type: 'asset/resource',
67+
},
68+
// Fonts and SVGs
69+
{
70+
test: /\.(woff(2)?|eot|ttf|otf|svg|)$/,
71+
type: 'asset/inline',
72+
},
73+
]
74+
},
75+
resolve: {
76+
extensions: ['.ts', '.js', '.css', '.mahal', '.scss'],
77+
alias: {
78+
"~": rootFolder,
79+
"@": path.join(rootFolder, 'src'),
80+
"@config": path.join(rootFolder, 'config'),
81+
"@components": path.join(rootFolder, 'src', 'components'),
82+
process: "process/browser"
83+
},
84+
},
85+
output: {
86+
filename: isEnvProduction ? 'js/[name].[contenthash:8].js' : 'js/[name].js',
87+
chunkFilename: isEnvProduction ? 'js/[name].[contenthash:8].chunk.js' : 'js/[name].chunk.js',
88+
path: path.resolve(rootFolder, 'dist'),
89+
publicPath: '/'
90+
},
91+
plugins: [
92+
new MahalPlugin({
93+
lang: 'js'
94+
}),
95+
new HtmlWebPackPlugin({
96+
cache: true,
97+
hash: true,
98+
template: 'src/index.html',
99+
minify: {
100+
collapseWhitespace: true,
101+
removeComments: true,
102+
removeRedundantAttributes: true,
103+
removeScriptTypeAttributes: true,
104+
removeStyleLinkTypeAttributes: true
105+
}
106+
}),
107+
new CleanWebpackPlugin(),
108+
new CopyPlugin({
109+
patterns: [{
110+
from: './assets/',
111+
to: ''
112+
}]
113+
}),
114+
new MiniCssExtractPlugin({
115+
filename: isEnvProduction ? 'css/[name].[contenthash:8].css' : 'css/[name].css',
116+
chunkFilename: isEnvProduction ? 'css/[name].[contenthash:8].chunk.css' : 'css/[name].chunk.css',
117+
}),
118+
119+
]
120+
};

mahal/config/webpack/dev.config.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const { merge } = require('webpack-merge');
2+
const path = require('path');
3+
const baseConfig = require('./base.config');
4+
5+
module.exports = merge(baseConfig, {
6+
devServer: {
7+
historyApiFallback: true,
8+
},
9+
});
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
const { merge } = require('webpack-merge')
2+
const baseConfig = require('./base.config')
3+
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
4+
5+
const prod = merge(baseConfig, {
6+
mode: 'production',
7+
devtool: false,
8+
output: {
9+
publicPath: '/',
10+
filename: 'js/[name].[contenthash].bundle.js',
11+
},
12+
optimization: {
13+
minimize: true,
14+
minimizer: [`...`, new CssMinimizerPlugin()],
15+
runtimeChunk: {
16+
name: 'runtime',
17+
},
18+
splitChunks: {
19+
chunks: 'all',
20+
maxInitialRequests: Infinity,
21+
minSize: 100000,
22+
maxSize: 1000000,
23+
cacheGroups: {
24+
vendor: {
25+
test: /[\\/]node_modules[\\/]/,
26+
name(module) {
27+
// get the name. E.g. node_modules/packageName/not/this/part.js
28+
// or node_modules/packageName
29+
const packageName = module.context.match(/[\\/]node_modules[\\/](.*?)([\\/]|$)/)[1];
30+
// console.log('package', packageName);
31+
// npm package names are URL-safe, but some servers don't like @ symbols
32+
return `npm.${packageName.replace('@', '')}`;
33+
},
34+
},
35+
},
36+
},
37+
},
38+
performance: {
39+
hints: false,
40+
maxEntrypointSize: 512000,
41+
maxAssetSize: 512000,
42+
},
43+
})
44+
45+
module.exports = prod;

0 commit comments

Comments
 (0)