This repository was archived by the owner on Nov 9, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathwebpack.config.js
More file actions
78 lines (75 loc) · 2.84 KB
/
webpack.config.js
File metadata and controls
78 lines (75 loc) · 2.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
const path = require('path');
const fs = require('fs');
const CompressionPlugin = require('compression-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const packagejson = JSON.parse(fs.readFileSync('./package.json'));
const PROD = process.env.NODE_ENV === 'production';
// --- Version replace in asg-service.ts ---
const asgServicePath = path.resolve(__dirname, 'src/asg-service.ts');
let asgServiceContent = fs.readFileSync(asgServicePath, 'utf8');
asgServiceContent = asgServiceContent.replace(/version.*"\d+\.\d+\.\d+"/, `version = "${packagejson.version}"`);
fs.writeFileSync(asgServicePath, asgServiceContent);
// --- Angular template cache (simple implementation) ---
const glob = require('glob');
const templateCachePath = path.resolve(__dirname, 'src/asg-templates.js');
const templateFiles = glob.sync('./src/views/**/*.html');
let templateCacheContent = `angular.module('angularSuperGallery').run(['$templateCache', function($templateCache) {\n`;
templateFiles.forEach(file => {
let content = fs.readFileSync(file, 'utf8')
.replace(/\\/g, '\\\\') // escape backslash
.replace(/'/g, "\\'") // escape single quote
.replace(/\r?\n/g, '\\n'); // escape newlines
// Change: key should be relative to src/ and not start with a slash
let key = file.replace(/^src/, ''); // removes './src/' from start
key = key.replace(/\\/g, '/'); // normalize slashes
templateCacheContent += ` $templateCache.put('${key}', '${content}');\n`;
console.log(`Added template: ${key}`); // Log added templates
});
templateCacheContent += '}]);\n';
templateCacheContent = templateCacheContent.replace(/button\\/g, 'button/').replace(/\\views\\/g, '/views/');
fs.writeFileSync(templateCachePath, templateCacheContent);
module.exports = {
mode: PROD ? 'production' : 'development',
entry: {
'angular-super-gallery.min': './src/asg.ts'
},
output: {
path: path.resolve(__dirname, 'dist'),
filename: '[name].js',
},
module: {
rules: [
{
test: /\.ts$/,
use: 'ts-loader',
exclude: /node_modules/
},
{
test: /\.scss$/,
use: [
MiniCssExtractPlugin.loader,
'css-loader',
'sass-loader'
]
},
{
test: /\.html$/,
use: 'raw-loader'
}
]
},
resolve: {
extensions: ['.ts', '.js']
},
plugins: [
new MiniCssExtractPlugin({
filename: 'angular-super-gallery.min.css'
}),
...(PROD ? [new CompressionPlugin({
algorithm: "gzip",
test: /\.(js|ts|css|html|svg)$/,
threshold: 10240,
minRatio: 0.8
})] : [])
]
};