Skip to content

Commit 552af6c

Browse files
committed
Added crossenv
Set incremental mode as true, set target as es6 in tsconfig.json
1 parent ce94a4b commit 552af6c

File tree

8 files changed

+19
-31
lines changed

8 files changed

+19
-31
lines changed

.babelrc.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
/**
22
* Created by: Andrey Polyakov (andrey@polyakov.im)
33
*/
4-
const {argv} = require('yargs');
54

65
module.exports = (api) => {
7-
const env = argv.env || [];
8-
const mode = !!env.find((value) => value === 'mode=dev')
9-
? 'development'
10-
: 'production';
6+
const mode = process.env.NODE_ENV ?? 'production';
117

128
// This caches the Babel config by environment.
139
api.cache.using(() => mode);

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
"author": "Andrey Polyakov <andrey@polyakov.im>",
1818
"main": "webpack.config.babel.js",
1919
"scripts": {
20-
"build": "webpack --config webpack.config.babel.js",
21-
"profile": "webpack --profile --json --config webpack.config.babel.js > ./dist/profile.json && webpack-bundle-analyzer ./dist/profile.json",
22-
"start": "webpack serve --env mode=dev --env isDevServer --env NODE_ENV=local --config webpack.config.babel.js",
20+
"build": "cross-env NODE_ENV=production webpack --config webpack.config.babel.js",
21+
"profile": "cross-env NODE_ENV=production webpack --profile --json --config webpack.config.babel.js > ./dist/profile.json && webpack-bundle-analyzer ./dist/profile.json",
22+
"start": "cross-env WEBPACK_IS_DEV_SERVER=true NODE_ENV=development webpack serve --config webpack.config.babel.js",
2323
"release": "npm version patch"
2424
},
2525
"husky": {
@@ -60,6 +60,7 @@
6060
"clean-webpack-plugin": "~3.0.0",
6161
"copy-webpack-plugin": "~6.3.0",
6262
"core-js": "~3.7.0",
63+
"cross-env": "^7.0.3",
6364
"css-loader": "~5.0.0",
6465
"cssnano": "~4.1.10",
6566
"eslint": "~7.13.0",
@@ -104,8 +105,7 @@
104105
"webpack-bundle-analyzer": "~4.1.0",
105106
"webpack-cli": "~4.5.0",
106107
"webpack-dev-server": "~3.11.2",
107-
"webpack-merge": "~5.3.0",
108-
"yargs": "~16.1.0"
108+
"webpack-merge": "~5.3.0"
109109
},
110110
"importSort": {
111111
".ts, .tsx": {

tsconfig.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"compilerOptions": {
33
"outDir": "./dist",
44
"module": "esnext",
5-
"target": "es5",
5+
"target": "es6",
66
"lib": ["es6", "dom"],
77
"sourceMap": true,
88
"allowJs": true,
@@ -23,7 +23,9 @@
2323
},
2424
"allowSyntheticDefaultImports": true,
2525
"esModuleInterop": true,
26-
"importsNotUsedAsValues": "preserve"
26+
"importsNotUsedAsValues": "preserve",
27+
"incremental": true
2728
},
28-
"exclude": ["node_modules", "webpack"]
29+
"include": ["src"],
30+
"exclude": ["**/node_modules", "**/.*/"]
2931
}

webpack.config.babel.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import merge from 'webpack-merge';
55

66
import baseConfig from './webpack/base';
77
import devConfig from './webpack/dev';
8-
import {isProd} from './webpack/utils/env';
98
import prodConfig from './webpack/prod';
9+
import {isProd} from './webpack/utils/env';
1010

1111
export default () =>
1212
isProd ? merge(baseConfig, prodConfig) : merge(baseConfig, devConfig);

webpack/plugins/pluginCleanWebpack.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@
44
import {CleanWebpackPlugin} from 'clean-webpack-plugin';
55

66
const config = {
7-
cleanOnceBeforeBuildPatterns: ['**/*', '!profile.json'],
7+
cleanOnceBeforeBuildPatterns: [
8+
'**/*',
9+
'!profile.json',
10+
'!tsconfig.tsbuildinfo',
11+
],
812
};
913

1014
export const cleanWebpackPlugin = new CleanWebpackPlugin(config);

webpack/plugins/pluginForkTsChecker.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ const config = {
1313
configFile: join(rootDir, '/tsconfig.json'),
1414
},
1515
eslint: {enabled: true, files: '../src/**/*.{ts,tsx,js,jsx}'},
16-
logger: {infrastructure: 'silent', issues: 'console'},
1716
};
1817

1918
export const forkTsCheckerWebpackPlugin = new ForkTsCheckerWebpackPlugin(

webpack/utils/env.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,8 @@
33
*/
44
import {join} from 'path';
55

6-
import {parseArguments} from './helpers';
7-
8-
const parsedArguments = parseArguments();
9-
export const mode = parsedArguments.mode ?? 'production';
10-
export const isDevServer = parsedArguments.isDevServer ?? false;
6+
export const mode = process.env.NODE_ENV ?? 'production';
7+
export const isDevServer = process.env.WEBPACK_IS_DEV_SERVER === 'true';
118
export const isProd = mode === 'production';
129
export const isDev = !isProd;
1310
export const rootDir = join(__dirname, '../../');

webpack/utils/helpers.js

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,6 @@
11
/**
22
* Created by: Andrey Polyakov (andrey@polyakov.im)
33
*/
4-
import {argv} from 'yargs';
5-
6-
export const parseArguments = () => {
7-
const {env = []} = argv;
8-
return env.reduce((accumulator, currentValue) => {
9-
const [key, value = true] = currentValue.split('=');
10-
return {...accumulator, [key]: value};
11-
}, {});
12-
};
13-
144
export const arrayFilterEmpty = (array) => array.filter((x) => !!x);
155

166
export const pathRewrite = (localUrl, remoteUrl) => (path) =>

0 commit comments

Comments
 (0)