1
0
Fork 0
mirror of https://github.com/Findus23/lw1.at.git synced 2024-09-16 12:13:44 +02:00

use typescript for webpack config

This commit is contained in:
Lukas Winkler 2020-12-21 14:31:16 +01:00
parent 9228c59c21
commit 2ff9524ab3
Signed by: lukas
GPG key ID: 54DE4D798D244853
9 changed files with 1917 additions and 2385 deletions

View file

@ -4,15 +4,17 @@
"version": "1.0.0",
"author": "Lukas Winkler <l.winkler23@mailbox.org>",
"private": true,
"scripts": {
"dev": "cross-env NODE_ENV=development webpack-dev-server --mode development --content-base dist/ --hot",
"build": "cross-env NODE_ENV=production webpack --mode production --progress --hide-modules",
"json": "cross-env NODE_ENV=production webpack --mode production --profile --json > stats.json"
"build": "NODE_ENV=\"production\" TS_NODE_PROJECT=\"tsconfig-for-webpack-config.json\" webpack --config webpack.prod.ts",
"dev": "TS_NODE_PROJECT=\"tsconfig-for-webpack-config.json\" webpack serve --config webpack.dev.ts --hot",
"json": "TS_NODE_PROJECT=\"tsconfig-for-webpack-config.json\" webpack --config webpack.prod.ts --profile --json > stats.json"
},
"dependencies": {
"balloon-css": "^1.0.4",
"copy-webpack-plugin": "^7.0.0",
"highlight.js": "^10.1.1",
"markdown-it": "^11.0.0",
"markdown-it": "^12.0.4",
"mathjax-node-page": "^3.0.1",
"mathjax3": "^3.0.0-beta.2",
"milligram": "git+https://github.com/Findus23/milligram.git#0fde381605c1159f39efb5c33c9600331fec4e2e",
@ -21,20 +23,28 @@
"raven-js": "^3.27.0",
"vue": "^2.5.13",
"vue-head": "^2.0.12",
"vue-router": "^3.0.1"
"vue-router": "^3.0.1",
"webpack-merge": "^5.7.2"
},
"devDependencies": {
"@babel/core": "^7.0.0-beta.40",
"@babel/plugin-syntax-dynamic-import": "^7.2.0",
"@babel/preset-env": "^7.0.0-beta.40",
"@types/compression-webpack-plugin": "^6.0.1",
"@types/copy-webpack-plugin": "^6.3.0",
"@types/mini-css-extract-plugin": "^1.2.2",
"@types/node": "^14.14.14",
"@types/webpack": "^4.41.25",
"@types/webpack-dev-server": "^3.11.1",
"@types/webpack-subresource-integrity": "^1.2.0",
"autoprefixer": "^10.0.1",
"babel-eslint": "^10.0.1",
"babel-loader": "^8.0.0-beta.0",
"blurhash": "^1.1.3",
"clean-webpack-plugin": "^3.0.0",
"compression-webpack-plugin": "^6.0.2",
"compression-webpack-plugin": "^7.1.0",
"cross-env": "^7.0.0",
"css-loader": "^4.3.0",
"css-loader": "^5.0.1",
"eslint": "^7.4.0",
"eslint-loader": "^4.0.2",
"eslint-plugin-html": "^6.0.0",
@ -44,15 +54,17 @@
"js-yaml": "^3.12.0",
"license-webpack-plugin": "^2.0.0-alpha.7",
"mini-css-extract-plugin": "^1.0.0",
"node-sass": "^4.7.2",
"node-sass": "^5.0.0",
"postcss-loader": "^4.0.4",
"prerender-spa-plugin": "^3.0.0-beta.2",
"sass-loader": "^10.0.3",
"sharp": "^0.26.1",
"ts-node": "^9.1.1",
"typescript": "^4.1.3",
"vue-loader": "^15.2.4",
"vue-template-compiler": "^2.5.13",
"webpack": "^4.12.0",
"webpack-cli": "^3.0.1",
"webpack": "^5.11.0",
"webpack-cli": "^4.2.0",
"webpack-dev-server": "^3.1.1",
"webpack-subresource-integrity": "^1.1.0-rc.4"
},

View file

@ -1,7 +1,7 @@
export default class MatomoTracker {
init() {
if (typeof _paq === 'undefined' && !window.__PRERENDER_INJECTED) { // should only occur with hot reloading
let _paq = _paq || [];
let _paq = window._paq || [];
_paq.push(['setRequestMethod', 'POST']);
_paq.push(['enableHeartBeatTimer']);

View file

@ -6,12 +6,12 @@ import MatomoTracker from './MatomoTracker';
const hljs = require('./highlightjs.scss');
const style = require('./global_styles.scss');
const Raven = require("raven-js");
const RavenVue = require("raven-js/plugins/vue");
Raven
.config('https://c10d5f4a5b714efdbcaceaaedf22a75d@sentry.lw1.at/11')
.addPlugin(RavenVue)
.install();
// const Raven = require("raven-js");
// const RavenVue = require("raven-js/plugins/vue");
// Raven
// .config('https://c10d5f4a5b714efdbcaceaaedf22a75d@sentry.lw1.at/11')
// .addPlugin(RavenVue)
// .install();
Vue.use(VueHead);

View file

@ -0,0 +1,7 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"esModuleInterop": true
}
}

71
tsconfig.json Normal file
View file

@ -0,0 +1,71 @@
{
"compilerOptions": {
/* Basic Options */
"target": "es5",
/* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
"module": "esnext",
/* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
"moduleResolution": "node",
"lib": [
"dom",
"es5"
],
// "lib": [], /* Specify library files to be included in the compilation. */
// "allowJs": true, /* Allow javascript files to be compiled. */
// "checkJs": true, /* Report errors in .js files. */
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
// "declaration": true, /* Generates corresponding '.d.ts' file. */
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
// "sourceMap": true, /* Generates corresponding '.map' file. */
// "outFile": "./", /* Concatenate and emit output to single file. */
// "outDir": "./", /* Redirect output structure to the directory. */
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
// "composite": true, /* Enable project compilation */
// "incremental": true, /* Enable incremental compilation */
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
// "removeComments": true, /* Do not emit comments to output. */
// "noEmit": true, /* Do not emit outputs. */
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
/* Strict Type-Checking Options */
"strict": true,
/* Enable all strict type-checking options. */
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
// "strictNullChecks": true, /* Enable strict null checks. */
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
// "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
/* Additional Checks */
// "noUnusedLocals": true, /* Report errors on unused locals. */
// "noUnusedParameters": true, /* Report errors on unused parameters. */
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
/* Module Resolution Options */
// "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
// "typeRoots": [], /* List of folders to include type definitions from. */
// "types": [], /* Type declaration files to be included in compilation. */
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
"esModuleInterop": true
/* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
/* Source Map Options */
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
/* Experimental Options */
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
}
}

View file

@ -1,26 +1,40 @@
let path = require('path');
let webpack = require('webpack');
let {CleanWebpackPlugin} = require('clean-webpack-plugin');
let HtmlWebpackPlugin = require('html-webpack-plugin');
let SriPlugin = require('webpack-subresource-integrity');
let CompressionPlugin = require('compression-webpack-plugin');
let MiniCssExtractPlugin = require("mini-css-extract-plugin");
let VueLoaderPlugin = require('vue-loader/lib/plugin');
let PrerenderSPAPlugin = require('prerender-spa-plugin');
let PuppeteerRenderer = PrerenderSPAPlugin.PuppeteerRenderer;
let LicenseWebpackPlugin = require('license-webpack-plugin').LicenseWebpackPlugin;
import * as path from 'path';
import * as webpack from 'webpack';
import HtmlWebpackPlugin from "html-webpack-plugin";
import MiniCssExtractPlugin from "mini-css-extract-plugin";
import {VueLoaderPlugin} from "vue-loader";
const commitHash = require('child_process').execSync('git rev-parse --short HEAD').toString();
module.exports = {
entry: {app: './src/main.js'},
let production = process.env.NODE_ENV === "production"
const config: webpack.Configuration = {
entry: "./src/main.js",
output: {
path: path.resolve(__dirname, './dist'),
publicPath: '/',
filename: '[name]-build-[hash].js',
filename: "[name].[contenthash].js",
chunkFilename: "[name].[contenthash].js",
path: path.resolve(__dirname, "dist"),
crossOriginLoading: "anonymous"
},
mode: process.env.NODE_ENV,
resolve: {
extensions: [".ts", ".tsx", ".js", ".json"]
},
plugins: [
new HtmlWebpackPlugin({
template: "my-index.ejs",
}),
// new webpack.IgnorePlugin(/^jquery/),
new webpack.DefinePlugin({
"process.env": {
API_KEY: '"' + process.env.API_KEY + '"'
},
"COMMITHASH": commitHash
}),
new webpack.ContextReplacementPlugin(/moment[\/\\]locale$/, /de|en/),
new VueLoaderPlugin() as any,
],
module: {
rules: [
{
@ -28,7 +42,6 @@ module.exports = {
loader: 'vue-loader',
options: {
sourceMap: true,
extractCSS: process.env.NODE_ENV === 'production',
cssSourceMap: true,
transformToRequire: {
video: ['src', 'poster'],
@ -38,6 +51,11 @@ module.exports = {
},
}
},
{
test: /\.tsx?$/,
use: "ts-loader",
exclude: /node_modules/
},
{
test: /\.js$/,
exclude: file => (
@ -63,16 +81,55 @@ module.exports = {
}
},
{
test: /\.(asc)$/,
test: /\.scss$/,
use: [
!production
? "vue-style-loader"
: MiniCssExtractPlugin.loader,
{
loader: 'file-loader',
loader: 'css-loader',
options: {
name: '[folder]/[name].[ext]?hash=[contenthash]'
esModule:false
}
}
},
{
loader: "postcss-loader",
options: {
postcssOptions: {
plugins: [require("autoprefixer")()]
}
}
},
"sass-loader"
]
},
{
test: /\.css$/,
use: [
!production
? 'vue-style-loader'
: MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
options: {
importLoaders: 1,
esModule:false
}
},
{
loader: "postcss-loader",
options: {
postcssOptions: {
plugins: [require('autoprefixer')()]
}
}
},
]
},
{
test: /\.yaml$/,
loader: path.resolve('data-loader.js'),
},
{
test: /\.(png|jpg|gif|svg)$/,
use: [
@ -95,137 +152,8 @@ module.exports = {
},
],
},
{
test: /\.yaml$/,
loader: path.resolve('data-loader.js'),
},
{
test: /\.scss$/,
use: [
process.env.NODE_ENV !== 'production'
? 'vue-style-loader'
: MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
options: {
esModule:false
}
},
{
loader: "postcss-loader",
options: {
postcssOptions: {
plugins: [require('autoprefixer')()]
}
}
},
'sass-loader'
]
},
{
test: /\.css$/,
use: [
process.env.NODE_ENV !== 'production'
? 'vue-style-loader'
: MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
options: {
importLoaders: 1,
esModule:false
}
},
{
loader: "postcss-loader",
options: {
postcssOptions: {
plugins: [require('autoprefixer')()]
}
}
},
]
}
]
},
devServer: {
historyApiFallback: true,
noInfo: true,
overlay: true
},
performance: {
hints: false
},
optimization: {
namedModules: true
},
devtool: 'source-map',
plugins: [
new HtmlWebpackPlugin({
title: 'My App',
template: 'my-index.ejs',
// devServer: process.env.NODE_ENV === 'production' ? '' : 'http://localhost:8081',
}),
new MiniCssExtractPlugin({
filename: "[name]-[hash].css",
chunkFilename: "[name]-[hash].css"
}),
new SriPlugin({
hashFuncNames: ['sha256'],
enabled: process.env.NODE_ENV === 'production',
}),
new webpack.ContextReplacementPlugin(/moment[\/\\]locale$/, /de|en/),
new VueLoaderPlugin(),
new LicenseWebpackPlugin({
perChunkOutput: false,
outputFilename: "licenses.txt"
})
]
}
};
if (process.env.NODE_ENV === 'production') {
module.exports.optimization = {
splitChunks: {
chunks: 'all',
name: "commons"
},
minimize: true
};
module.exports.devtool = '#source-map';
// http://vue-loader.vuejs.org/en/workflow/production.html
module.exports.plugins = (module.exports.plugins || []).concat([
new CleanWebpackPlugin(),
new webpack.HashedModuleIdsPlugin({
hashFunction: 'sha256',
hashDigest: 'hex',
hashDigestLength: 20
}),
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: '"production"'
},
"COMMITHASH": commitHash
}),
new CompressionPlugin({
test: /\.(js|css|html)/
}),
// new SriPlugin({
// hashFuncNames: ['sha256'],
// }),
]);
if (process.env.PRERENDER !== 'disabled') {
module.exports.plugins = (module.exports.plugins || []).concat([
new PrerenderSPAPlugin({
staticDir: path.join(__dirname, 'dist'), // The path to the folder where index.html is.
routes: require("./routes"), // List of routes to prerender.
renderer: new PuppeteerRenderer({
headless: true,
inject: {
prerender: true
},
maxConcurrentRoutes: 4,
}),
})
]);
}
}
export default config;

19
webpack.dev.ts Normal file
View file

@ -0,0 +1,19 @@
import * as webpack from "webpack";
import merge from "webpack-merge";
import common from './webpack.common';
const config: webpack.Configuration = merge(common, {
mode: "development",
devtool: "eval-cheap-source-map",
devServer: {
historyApiFallback: true,
noInfo: true,
overlay: true
},
plugins: [
new webpack.HotModuleReplacementPlugin()
]
})
export default config

71
webpack.prod.ts Normal file
View file

@ -0,0 +1,71 @@
import * as webpack from "webpack";
import merge from "webpack-merge";
import common from './webpack.common';
import {LicenseWebpackPlugin} from "license-webpack-plugin";
import SriPlugin from 'webpack-subresource-integrity';
// @ts-ignore
import PrerenderSPAPlugin from 'prerender-spa-plugin';
const PuppeteerRenderer = PrerenderSPAPlugin.PuppeteerRenderer;
import CompressionPlugin from 'compression-webpack-plugin';
import CopyWebpackPlugin from "copy-webpack-plugin";
import {CleanWebpackPlugin} from "clean-webpack-plugin";
import MiniCssExtractPlugin from "mini-css-extract-plugin";
import * as path from 'path';
const config: webpack.Configuration = merge(common, {
mode: "production",
optimization: {
splitChunks: {
name: "commons"
},
minimize: true,
moduleIds: "deterministic"
},
devtool: "source-map",
plugins: [
new SriPlugin({
hashFuncNames: ["sha256"],
enabled: true
}),
new LicenseWebpackPlugin({
// perChunkOutput: false
licenseTextOverrides: {
blurhash: 'MIT'
}
}) as any,
new CleanWebpackPlugin(),
// new CopyWebpackPlugin({patterns: [{from: "icon", to: "icon"}]}),
// new CopyWebpackPlugin({patterns: [{from: "licenses.txt", to: "licenses.txt"}]}),
new webpack.LoaderOptionsPlugin({
minimize: true
}),
new MiniCssExtractPlugin({
filename: "[name].[contenthash].css",
chunkFilename: "[id].[contenthash].css"
}),
new CompressionPlugin({
test: /\.(js|css|html)/
}),
]
})
if (process.env.PRERENDER !== 'disabled') {
module.exports.plugins = (module.exports.plugins || []).concat([
new PrerenderSPAPlugin({
staticDir: path.join(__dirname, 'dist'), // The path to the folder where index.html is.
routes: require("./routes"), // List of routes to prerender.
renderer: new PuppeteerRenderer({
headless: true,
inject: {
prerender: true
},
maxConcurrentRoutes: 4,
}),
})
]);
}
export default config

3854
yarn.lock

File diff suppressed because it is too large Load diff