mirror of
https://github.com/arthurfiorette/axios-cache-interceptor.git
synced 2025-12-08 17:36:16 +00:00
build: build everything from webpack
This commit is contained in:
parent
8415f4478b
commit
f1604287a4
@ -1,8 +1,23 @@
|
||||
/node_modules
|
||||
# Javascript
|
||||
coverage
|
||||
node_modules
|
||||
|
||||
/umd
|
||||
/cjs
|
||||
/esm
|
||||
/dist
|
||||
/types
|
||||
|
||||
# Random
|
||||
/ignore
|
||||
/docs
|
||||
/esm
|
||||
/cjs
|
||||
/umd
|
||||
*.log
|
||||
|
||||
# Vscode
|
||||
.vscode/*
|
||||
!.vscode/launch.json
|
||||
|
||||
# Npm & Yarn
|
||||
package-lock.json
|
||||
.yarn/*
|
||||
!.yarn/releases
|
||||
!.yarn/plugins
|
||||
|
||||
@ -56,7 +56,6 @@ Licensed under the **MIT**. See [`LICENSE`](LICENSE) for more informations.
|
||||
|
||||
<br />
|
||||
|
||||
|
||||
[](https://app.fossa.com/projects/git%2Bgithub.com%2Farthurfiorette%2Faxios-cache-interceptor?ref=badge_large)
|
||||
|
||||
## Contact
|
||||
@ -64,4 +63,4 @@ Licensed under the **MIT**. See [`LICENSE`](LICENSE) for more informations.
|
||||
See my contact information on my [github profile](https://github.com/arthurfiorette) or
|
||||
open a new issue.
|
||||
|
||||
<br />
|
||||
<br />
|
||||
|
||||
@ -5,13 +5,18 @@
|
||||
|
||||
echo "\nStarting build...\n"
|
||||
|
||||
rm -rf cjs/ esm/ umd/
|
||||
rm -rf cjs/ esm/ umd/ types/
|
||||
mkdir cjs/ esm/ umd/ types/
|
||||
|
||||
echo "Target cleared...\n"
|
||||
|
||||
webpack --config build/webpack.config.js &
|
||||
tsc -p build/tsconfig.cjs.json &
|
||||
tsc -p build/tsconfig.esm.json &
|
||||
tsc -p build/tsconfig.types.json &
|
||||
echo "export * from '../types';" | tee \
|
||||
esm/index.d.ts esm/dev.d.ts \
|
||||
cjs/index.d.ts cjs/dev.d.ts \
|
||||
umd/index.d.ts umd/dev.d.ts umd/es6.d.ts \
|
||||
> /dev/null &
|
||||
|
||||
wait
|
||||
|
||||
|
||||
@ -6,7 +6,10 @@
|
||||
echo "\nStarting checking...\n"
|
||||
|
||||
es-check es5 umd/es5.js &
|
||||
es-check es6 umd/es6.js &
|
||||
es-check es6 umd/index.js cjs/index.js &
|
||||
es-check es2017 umd/dev.js cjs/dev.js &
|
||||
es-check es2017 esm/dev.js --module &
|
||||
es-check es6 esm/index.js --module &
|
||||
|
||||
wait
|
||||
|
||||
|
||||
@ -3,7 +3,6 @@
|
||||
"compilerOptions": {
|
||||
"module": "ESNext", // webpack converts to UMD
|
||||
"target": "ESNext",
|
||||
"outDir": "../umd",
|
||||
|
||||
// Emits all import helpers as an import to tslib
|
||||
// This allows webpack to be better at tree shaking
|
||||
@ -1,9 +0,0 @@
|
||||
{
|
||||
"extends": "../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"module": "CommonJS",
|
||||
"target": "ES2017",
|
||||
"outDir": "../cjs"
|
||||
},
|
||||
"include": ["../src"]
|
||||
}
|
||||
@ -1,9 +0,0 @@
|
||||
{
|
||||
"extends": "../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"module": "ESNext",
|
||||
"target": "ES2017",
|
||||
"outDir": "../esm"
|
||||
},
|
||||
"include": ["../src"]
|
||||
}
|
||||
10
build/tsconfig.types.json
Normal file
10
build/tsconfig.types.json
Normal file
@ -0,0 +1,10 @@
|
||||
{
|
||||
"extends": "../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"emitDeclarationOnly": true,
|
||||
"outDir": "../types",
|
||||
"declaration": true,
|
||||
"declarationMap": true
|
||||
},
|
||||
"include": ["../src"]
|
||||
}
|
||||
@ -3,6 +3,7 @@
|
||||
|
||||
const path = require('path');
|
||||
const TerserWebpackPlugin = require('terser-webpack-plugin');
|
||||
const { DefinePlugin } = require('webpack');
|
||||
|
||||
const root = (...p) => path.resolve(__dirname, '..', ...p);
|
||||
|
||||
@ -10,10 +11,21 @@ const root = (...p) => path.resolve(__dirname, '..', ...p);
|
||||
* @param {{
|
||||
* output: string;
|
||||
* esTarget: string;
|
||||
* libraryType: import('webpack').LibraryOptions['type'];
|
||||
* libraryName?: import('webpack').LibraryOptions['name'];
|
||||
* inlineDeps?: boolean;
|
||||
* devBuild?: boolean;
|
||||
* }} options
|
||||
* @returns {import('webpack').Configuration}
|
||||
*/
|
||||
const config = ({ output, esTarget }) => ({
|
||||
const config = ({
|
||||
output,
|
||||
esTarget,
|
||||
libraryType,
|
||||
libraryName,
|
||||
inlineDeps = false,
|
||||
devBuild = false
|
||||
}) => ({
|
||||
mode: 'production',
|
||||
|
||||
entry: root('src', 'index.ts'),
|
||||
@ -23,20 +35,27 @@ const config = ({ output, esTarget }) => ({
|
||||
globalObject: `typeof self !== 'undefined' ? self : this`,
|
||||
filename: output + '.js',
|
||||
sourceMapFilename: output + '.map',
|
||||
chunkFormat: 'module',
|
||||
module: libraryType === 'module',
|
||||
library: {
|
||||
type: 'umd',
|
||||
name: 'AxiosCacheInterceptor'
|
||||
},
|
||||
chunkFormat: 'module'
|
||||
type: libraryType,
|
||||
name: libraryName
|
||||
}
|
||||
},
|
||||
|
||||
target: esTarget,
|
||||
devtool: devBuild ? 'source-map' : false,
|
||||
|
||||
resolve: {
|
||||
extensions: ['.ts', '.js']
|
||||
},
|
||||
experiments: { outputModule: true },
|
||||
resolve: { extensions: ['.ts', '.js'] },
|
||||
|
||||
devtool: 'source-map',
|
||||
externals: inlineDeps
|
||||
? {
|
||||
'cache-parser': 'cache-parser',
|
||||
'object-code': 'object-code',
|
||||
'fast-defer': 'fast-defer'
|
||||
}
|
||||
: undefined,
|
||||
|
||||
module: {
|
||||
rules: [
|
||||
@ -45,7 +64,7 @@ const config = ({ output, esTarget }) => ({
|
||||
test: /\.(ts|js)$/,
|
||||
loader: 'ts-loader',
|
||||
options: {
|
||||
configFile: root('build', 'tsconfig.umd.json'),
|
||||
configFile: root('build', 'tsconfig.build.json'),
|
||||
compilerOptions: {
|
||||
target: esTarget
|
||||
}
|
||||
@ -55,22 +74,66 @@ const config = ({ output, esTarget }) => ({
|
||||
},
|
||||
|
||||
optimization: {
|
||||
minimize: true,
|
||||
minimize: !devBuild,
|
||||
sideEffects: true,
|
||||
removeEmptyChunks: true,
|
||||
mergeDuplicateChunks: true,
|
||||
concatenateModules: true,
|
||||
minimizer: [new TerserWebpackPlugin({ parallel: true })]
|
||||
}
|
||||
},
|
||||
|
||||
plugins: [new DefinePlugin({ __DEV__: devBuild })]
|
||||
});
|
||||
|
||||
module.exports = [
|
||||
// ESModule
|
||||
config({
|
||||
esTarget: 'es2015', //es6
|
||||
output: 'umd/es6'
|
||||
}),
|
||||
config({
|
||||
esTarget: 'es5',
|
||||
output: 'umd/es5'
|
||||
esTarget: 'es2015',
|
||||
output: 'esm/index',
|
||||
libraryType: 'module',
|
||||
inlineDeps: true
|
||||
}),
|
||||
config({
|
||||
esTarget: 'es2017',
|
||||
output: 'umd/index'
|
||||
output: 'esm/dev',
|
||||
libraryType: 'module',
|
||||
inlineDeps: true,
|
||||
devBuild: true
|
||||
}),
|
||||
|
||||
// CommonJS
|
||||
config({
|
||||
esTarget: 'es2015',
|
||||
output: 'cjs/index',
|
||||
libraryType: 'commonjs2',
|
||||
inlineDeps: true
|
||||
}),
|
||||
config({
|
||||
esTarget: 'es2017',
|
||||
output: 'cjs/dev',
|
||||
libraryType: 'commonjs2',
|
||||
inlineDeps: true,
|
||||
devBuild: true
|
||||
}),
|
||||
|
||||
// UMD
|
||||
config({
|
||||
esTarget: 'es2015',
|
||||
output: 'umd/index',
|
||||
libraryType: 'umd',
|
||||
libraryName: 'AxiosCacheInterceptor'
|
||||
}),
|
||||
config({
|
||||
esTarget: 'es2017',
|
||||
output: 'umd/dev',
|
||||
libraryType: 'umd',
|
||||
libraryName: 'AxiosCacheInterceptor',
|
||||
devBuild: true
|
||||
}),
|
||||
config({
|
||||
esTarget: 'es5',
|
||||
output: 'umd/es5',
|
||||
libraryType: 'umd',
|
||||
libraryName: 'AxiosCacheInterceptor'
|
||||
})
|
||||
];
|
||||
|
||||
13
package.json
13
package.json
@ -6,13 +6,13 @@
|
||||
"types": "./cjs/index.d.ts",
|
||||
"module": "./esm/index.js",
|
||||
"exports": {
|
||||
"import": "./esm/index.js",
|
||||
"require": "./cjs/index.js",
|
||||
"default": "./umd/es6.js"
|
||||
"import": "./esm/index.js",
|
||||
"require": "./cjs/index.js",
|
||||
"default": "./umd/index.js"
|
||||
},
|
||||
"browser": "./umd/es6.js",
|
||||
"jsdelivr": "./umd/es6.js",
|
||||
"unpkg": "./umd/es6.js",
|
||||
"browser": "./umd/index.js",
|
||||
"jsdelivr": "./umd/index.js",
|
||||
"unpkg": "./umd/index.js",
|
||||
"sideEffects": false,
|
||||
"runkitExampleFilename": "./examples/runkit.js",
|
||||
"scripts": {
|
||||
@ -44,6 +44,7 @@
|
||||
"cjs/",
|
||||
"esm/",
|
||||
"src/",
|
||||
"types/",
|
||||
"examples/"
|
||||
],
|
||||
"author": {
|
||||
|
||||
@ -59,7 +59,7 @@
|
||||
// "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */
|
||||
// "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */
|
||||
"newLine": "lf" /* Set the newline character for emitting files. */,
|
||||
// "stripInternal": true, /* Disable emitting declarations that have `@internal` in their JSDoc comments. */
|
||||
"stripInternal": true, /* Disable emitting declarations that have `@internal` in their JSDoc comments. */
|
||||
// "noEmitHelpers": true, /* Disable generating custom helper functions like `__extends` in compiled output. */
|
||||
// "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
|
||||
// "preserveConstEnums": true, /* Disable erasing `const enum` declarations in generated code. */
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user