Skip to content

Commit

Permalink
Added crossenv
Browse files Browse the repository at this point in the history
Set incremental mode as true, set target as es6 in tsconfig.json
  • Loading branch information
glook committed Feb 25, 2021
1 parent ce94a4b commit 552af6c
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 31 deletions.
6 changes: 1 addition & 5 deletions .babelrc.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
/**
* Created by: Andrey Polyakov ([email protected])
*/
const {argv} = require('yargs');

module.exports = (api) => {
const env = argv.env || [];
const mode = !!env.find((value) => value === 'mode=dev')
? 'development'
: 'production';
const mode = process.env.NODE_ENV ?? 'production';

// This caches the Babel config by environment.
api.cache.using(() => mode);
Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
"author": "Andrey Polyakov <[email protected]>",
"main": "webpack.config.babel.js",
"scripts": {
"build": "webpack --config webpack.config.babel.js",
"profile": "webpack --profile --json --config webpack.config.babel.js > ./dist/profile.json && webpack-bundle-analyzer ./dist/profile.json",
"start": "webpack serve --env mode=dev --env isDevServer --env NODE_ENV=local --config webpack.config.babel.js",
"build": "cross-env NODE_ENV=production webpack --config webpack.config.babel.js",
"profile": "cross-env NODE_ENV=production webpack --profile --json --config webpack.config.babel.js > ./dist/profile.json && webpack-bundle-analyzer ./dist/profile.json",
"start": "cross-env WEBPACK_IS_DEV_SERVER=true NODE_ENV=development webpack serve --config webpack.config.babel.js",
"release": "npm version patch"
},
"husky": {
Expand Down Expand Up @@ -60,6 +60,7 @@
"clean-webpack-plugin": "~3.0.0",
"copy-webpack-plugin": "~6.3.0",
"core-js": "~3.7.0",
"cross-env": "^7.0.3",
"css-loader": "~5.0.0",
"cssnano": "~4.1.10",
"eslint": "~7.13.0",
Expand Down Expand Up @@ -104,8 +105,7 @@
"webpack-bundle-analyzer": "~4.1.0",
"webpack-cli": "~4.5.0",
"webpack-dev-server": "~3.11.2",
"webpack-merge": "~5.3.0",
"yargs": "~16.1.0"
"webpack-merge": "~5.3.0"
},
"importSort": {
".ts, .tsx": {
Expand Down
8 changes: 5 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"compilerOptions": {
"outDir": "./dist",
"module": "esnext",
"target": "es5",
"target": "es6",
"lib": ["es6", "dom"],
"sourceMap": true,
"allowJs": true,
Expand All @@ -23,7 +23,9 @@
},
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"importsNotUsedAsValues": "preserve"
"importsNotUsedAsValues": "preserve",
"incremental": true
},
"exclude": ["node_modules", "webpack"]
"include": ["src"],
"exclude": ["**/node_modules", "**/.*/"]
}
2 changes: 1 addition & 1 deletion webpack.config.babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import merge from 'webpack-merge';

import baseConfig from './webpack/base';
import devConfig from './webpack/dev';
import {isProd} from './webpack/utils/env';
import prodConfig from './webpack/prod';
import {isProd} from './webpack/utils/env';

export default () =>
isProd ? merge(baseConfig, prodConfig) : merge(baseConfig, devConfig);
6 changes: 5 additions & 1 deletion webpack/plugins/pluginCleanWebpack.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
import {CleanWebpackPlugin} from 'clean-webpack-plugin';

const config = {
cleanOnceBeforeBuildPatterns: ['**/*', '!profile.json'],
cleanOnceBeforeBuildPatterns: [
'**/*',
'!profile.json',
'!tsconfig.tsbuildinfo',
],
};

export const cleanWebpackPlugin = new CleanWebpackPlugin(config);
1 change: 0 additions & 1 deletion webpack/plugins/pluginForkTsChecker.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ const config = {
configFile: join(rootDir, '/tsconfig.json'),
},
eslint: {enabled: true, files: '../src/**/*.{ts,tsx,js,jsx}'},
logger: {infrastructure: 'silent', issues: 'console'},
};

export const forkTsCheckerWebpackPlugin = new ForkTsCheckerWebpackPlugin(
Expand Down
7 changes: 2 additions & 5 deletions webpack/utils/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@
*/
import {join} from 'path';

import {parseArguments} from './helpers';

const parsedArguments = parseArguments();
export const mode = parsedArguments.mode ?? 'production';
export const isDevServer = parsedArguments.isDevServer ?? false;
export const mode = process.env.NODE_ENV ?? 'production';
export const isDevServer = process.env.WEBPACK_IS_DEV_SERVER === 'true';
export const isProd = mode === 'production';
export const isDev = !isProd;
export const rootDir = join(__dirname, '../../');
Expand Down
10 changes: 0 additions & 10 deletions webpack/utils/helpers.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
/**
* Created by: Andrey Polyakov ([email protected])
*/
import {argv} from 'yargs';

export const parseArguments = () => {
const {env = []} = argv;
return env.reduce((accumulator, currentValue) => {
const [key, value = true] = currentValue.split('=');
return {...accumulator, [key]: value};
}, {});
};

export const arrayFilterEmpty = (array) => array.filter((x) => !!x);

export const pathRewrite = (localUrl, remoteUrl) => (path) =>
Expand Down

0 comments on commit 552af6c

Please sign in to comment.