首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在小型化中更新到节点9的结果

在小型化中更新到节点9的结果
EN

Stack Overflow用户
提问于 2018-04-09 21:09:02
回答 1查看 73关注 0票数 0

我希望你能帮我解决这个问题。我有一个使用了Webpack和React的项目。如果我将Node从v6更新到9,代码就会缩小。如果我将Node降级回v6,一切都会恢复原样。我想知道为什么会发生这种事?据我所知,缩小应该是按需发生的事情。Node 9是否以某种方式强制缩小化?这是我的package.json

代码语言:javascript
复制
    {
  "name": "tgc-ui",
  "version": "1.0.0",
  "description": "table-grid-ui",
  "main": "index.js",
  "scripts": {
    "test": "mocha --compilers js:babel-core/register --require test/helpers/browser.js test/*/*.spec.js"
  },
  "repository": {
    "type": "git",
    "url": "ssh://git@stash.idalko.com:7999/ip/tgc-ui.git"
  },
  "keywords": [
    "table",
    "grid",
    "ui"
  ],
  "author": "idalko",
  "license": "ISC",
  "dependencies": {
    "@atlaskit/banner": "^2.4.2",
    "@atlaskit/button": "^5.4.8",
    "@atlaskit/checkbox": "^1.0.0",
    "@atlaskit/dynamic-table": "^7.2.0",
    "@atlaskit/field-text": "^4.1.2",
    "@atlaskit/flag": "^6.1.8",
    "@atlaskit/icon": "^7.0.0",
    "@atlaskit/inline-edit": "^4.5.6",
    "@atlaskit/inline-message": "^3.0.4",
    "@atlaskit/input": "^1.1.2",
    "@atlaskit/lozenge": "^3.4.2",
    "@atlaskit/modal-dialog": "^3.0.2",
    "@atlaskit/multi-select": "^7.1.7",
    "@atlaskit/single-select": "^3.0.0",
    "@atlaskit/spinner": "^2.2.3",
    "@atlaskit/tabs": "^2.0.0",
    "@atlaskit/tooltip": "^6.0.0",
    "axios": "^0.16.2",
    "bootstrap": "^3.3.7",
    "brace": "^0.11.0",
    "browser-locale": "^1.0.3",
    "moment": "^2.18.1",
    "moxios": "^0.4.0",
    "prop-types": "^15.5.10",
    "react": "^15.5.4",
    "react-ace": "^5.8.0",
    "react-addons-update": "^15.6.0",
    "react-autocomplete": "^1.7.2",
    "react-autosize-textarea": "^0.4.9",
    "react-autosuggest": "^9.3.2",
    "react-bootstrap": "^0.31.0",
    "react-copy-to-clipboard": "^5.0.1",
    "react-data-grid": "^2.0.53",
    "react-data-grid-addons": "^2.0.53",
    "react-datepicker": "^0.53.0",
    "react-datetime": "^2.10.1",
    "react-dom": "^15.5.4",
    "react-file-reader-input": "^1.1.4",
    "react-keybinding-component": "^0.5.0",
    "sortablejs": "^1.6.1",
    "string-hash": "^1.1.3",
    "styled-components": "^1.4.6",
    "uuid": "^3.1.0",
    "yarn": "^0.27.5"
  },
  "devDependencies": {
    "babel-core": "^6.25.0",
    "babel-loader": "^7.0.0",
    "babel-plugin-react-require": "^3.0.0",
    "babel-plugin-transform-es2015-destructuring": "^6.23.0",
    "babel-plugin-transform-object-rest-spread": "^6.26.0",
    "babel-plugin-transform-react-jsx": "^6.24.1",
    "babel-preset-env": "^1.6.1",
    "babel-preset-stage-2": "^6.24.1",
    "babel-polyfill": "^6.26.0",
    "babel-preset-es2015": "^6.24.1",
    "babel-preset-react": "^6.24.1",
    "chai": "^4.0.2",
    "css-loader": "^0.28.4",
    "enzyme": "^2.8.2",
    "file-loader": "^0.11.2",
    "jsdom": "^11.5.1",
    "mocha": "^3.4.2",
    "react": "^15.5.4",
    "react-test-renderer": "^15.5.4",
    "sinon": "^2.3.4",
    "style-loader": "^0.18.2",
    "uglify-js": "^3.0.23",
    "uglifyjs-webpack-plugin": "^0.4.6",
    "url-loader": "^0.5.9",
    "webpack": "^2.6.1"
  }
}

和webpack.config.js

代码语言:javascript
复制
const webpack = require("webpack");
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');

var path = require('path'),
    jsxPath  = 'src',
    jsPath = 'dist/lib',
    srcPath = path.join(__dirname, jsxPath);

var isProd = (process.env.NODE_ENV === 'production');
var uiVersion = (process.env.CI_VERSION === '0.1.0-SNAPSHOT') ? '' : `_${process.env.CI_VERSION}`;

var service = {
    jiracloud: './custom_modules/CloudUtilityService.jsx'
}[process.env.APP_ENV];

function getPlugins() {
    var plugins = [];

    plugins.push(new webpack.DefinePlugin({
        'process.env': {
            'CI_VERSION': JSON.stringify(process.env.CI_VERSION),
            'NODE_ENV': JSON.stringify(process.env.NODE_ENV),
            'APP_ENV': JSON.stringify(process.env.APP_ENV)
        }
    }));

    if (isProd) {
        plugins.push(new UglifyJSPlugin({
            compress: {
                warnings: false,
                screw_ie8: true,
                conditionals: true,
                unused: true,
                comparisons: true,
                sequences: true,
                dead_code: true,
                evaluate: true,
                if_return: true,
                join_vars: true
            },
            output: {
                comments: false
            }
        }));
    }

    return plugins;
}

module.exports = {
    entry: {
        errorLicense: [path.join(srcPath, 'license/ErrorLicense.jsx')],
        ducketConfiguration: [path.join(srcPath, 'ducketconfig/DucketConfig.jsx')],
        dataSourceConfiguration: [path.join(srcPath, 'datasource/DataSourcesPage.jsx')],
        ducket: [path.join(srcPath, 'grid/Grid.jsx')],
        serviceDesk: [path.join(srcPath, 'adjustment/servicedesk/ServiceDesk.jsx')],
        searchHelp: [path.join(srcPath, 'search/SearchHelp.jsx')]
    },
    output: {
        //path:path.resolve(__dirname, jsPath),
       path:path.resolve(__dirname, "../tgc/public/javascript"),
        filename: `[name]${uiVersion}.js`
    },
    module: {
        rules: [
            {
                test: /\.jsx?$/,
                exclude: /node_modules/,
                loaders:['babel-loader']
            },
            {
                test: /\.css$/,
                loader: "style-loader!css-loader"
            },
            {
                test: /\.(eot|woff|woff2|ttf|svg|png|jpe?g|gif)(\?\S*)?$/,
                loader: 'url-loader?limit=100000@name=[name][ext]'
            }
        ]
    },
    resolve: {
        alias: {
            'styled-components': path.resolve('./node_modules/styled-components/dist/styled-components.es.js'),
            'utility-service': path.resolve(service)
        }
    },
    plugins: getPlugins()
};

提前谢谢你。

Iev--

EN

回答 1

Stack Overflow用户

发布于 2018-04-09 21:26:20

Node从不强制缩写,您的webpack配置中的这段代码是:

代码语言:javascript
复制
if (isProd) {
    plugins.push(new UglifyJSPlugin({
        compress: {
            warnings: false,
            screw_ie8: true,
            conditionals: true,
            unused: true,
            comparisons: true,
            sequences: true,
            dead_code: true,
            evaluate: true,
            if_return: true,
            join_vars: true
        },
        output: {
            comments: false
        }
    }));
}

这可能无法在较旧版本的node上运行,因为您的devDependencies用于可能需要node.js > v6的uglify@3

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49733785

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档