我希望你能帮我解决这个问题。我有一个使用了Webpack和React的项目。如果我将Node从v6更新到9,代码就会缩小。如果我将Node降级回v6,一切都会恢复原样。我想知道为什么会发生这种事?据我所知,缩小应该是按需发生的事情。Node 9是否以某种方式强制缩小化?这是我的package.json
{
"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
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--
发布于 2018-04-09 21:26:20
Node从不强制缩写,您的webpack配置中的这段代码是:
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
https://stackoverflow.com/questions/49733785
复制相似问题