CHANGE strategy to use DefinePlugin over global variable

This commit is contained in:
Norbert de Langen 2019-04-26 16:07:13 +02:00
parent 27d587f4d2
commit 9ad60a30ff
6 changed files with 13 additions and 5 deletions

View File

@ -153,6 +153,7 @@ module.exports = {
{
files: ['**/*.d.ts'],
rules: {
'vars-on-top': ignore,
'no-var': ignore, // this is how typescript works
'spaced-comment': ignore,
},

View File

@ -82,6 +82,7 @@ const insertDynamicRoot = () => {
const draw = (newModule: DynamicComponentType): void => {
if (!platform) {
insertDynamicRoot();
// eslint-disable-next-line no-undef
if (typeof NODE_ENV === 'string' && NODE_ENV !== 'development') {
try {
enableProdMode();

2
app/angular/src/typings.d.ts vendored Normal file
View File

@ -0,0 +1,2 @@
// will be provided by the webpack define plugin
declare var NODE_ENV: string | undefined;

View File

@ -61,6 +61,7 @@ export default ({ configDir, configType, entries, dll, outputDir, cache, babelOp
// graphql sources check process variable
new DefinePlugin({
process: JSON.stringify(true),
NODE_ENV: JSON.stringify(process.env.NODE_ENV),
}),
// See https://github.com/graphql/graphql-language-service/issues/111#issuecomment-306723400
new ContextReplacementPlugin(/graphql-language-service-interface[/\\]dist/, /\.js$/),

View File

@ -1,5 +1,5 @@
import path from 'path';
import webpack from 'webpack';
import { DefinePlugin, HotModuleReplacementPlugin, ProgressPlugin } from 'webpack';
import Dotenv from 'dotenv-webpack';
import HtmlWebpackPlugin from 'html-webpack-plugin';
import CaseSensitivePathsPlugin from 'case-sensitive-paths-webpack-plugin';
@ -58,11 +58,15 @@ export default ({
}),
template: require.resolve(`../templates/index.ejs`),
}),
new webpack.DefinePlugin({ 'process.env': stringified }),
new DefinePlugin({
'process.env': stringified,
process: JSON.stringify(true),
NODE_ENV: JSON.stringify(process.env.NODE_ENV),
}),
isProd ? null : new WatchMissingNodeModulesPlugin(nodeModulesPaths),
isProd ? null : new webpack.HotModuleReplacementPlugin(),
isProd ? null : new HotModuleReplacementPlugin(),
new CaseSensitivePathsPlugin(),
quiet ? null : new webpack.ProgressPlugin(),
quiet ? null : new ProgressPlugin(),
new Dotenv({ silent: true }),
].filter(Boolean),
module: {

View File

@ -62,7 +62,6 @@
window.__REACT_DEVTOOLS_GLOBAL_HOOK__ = window.parent.__REACT_DEVTOOLS_GLOBAL_HOOK__;
window.__VUE_DEVTOOLS_GLOBAL_HOOK__ = window.parent.__VUE_DEVTOOLS_GLOBAL_HOOK__;
}
window.NODE_ENV = '%NODE_ENV%';
} catch (e) {
// eslint-disable-next-line no-console
console.warn('unable to connect to parent frame for connecting dev tools');