vux-loader 源文件不压缩空格

发布于 2022-09-12 02:39:51 字数 6421 浏览 39 评论 0

这个项目是之前别人建的, 经过好几手了,完全不知道哪里控制了在开发模式的时候源码被压缩了空格,压缩空格在页面很难断点调式,又不太熟悉webapck
如下图: 空格全无
image.png

源文件:
image.png

使用了的依赖包,主要是webpack3,vue,vux等主要依赖库

"dependencies": {
    "axios": "^0.18.0",
    "babel-polyfill": "^6.26.0",
    "copy-webpack-plugin": "^4.5.1",
    "element-ui": "^2.2.1",
    "gulp": "^3.9.1",
    "gulp-gzip": "^1.4.2",
    "gulp-oss": "^0.1.1",
    "html-image-compress": "^1.1.0",
    "jsencrypt": "3.0.0-rc.1",
    "koa": "^2.5.0",
    "koa-bodyparser": "^4.2.0",
    "koa-redis": "^3.1.2",
    "koa-router": "^7.4.0",
    "koa-static": "^4.0.2",
    "lodash": "^4.17.5",
    "log4js": "^2.5.3",
    "md5": "^2.2.1",
    "merge": "^1.2.1",
    "moment": "^2.22.1",
    "sequelize": "^4.35.2",
    "vue": "^2.5.15",
    "vue-router": "^3.0.1",
    "vuex": "^3.0.1",
    "vuex-router-sync": "^5.0.0",
    "vux": "^2.9.0"
  },
  "devDependencies": {
    "autoprefixer": "^8.1.0",
    "babel-core": "^6.26.0",
    "babel-loader": "^7.1.4",
    "babel-plugin-component": "^1.1.0",
    "babel-plugin-syntax-jsx": "^6.18.0",
    "babel-plugin-transform-runtime": "^6.23.0",
    "babel-plugin-transform-vue-jsx": "^3.7.0",
    "babel-preset-env": "^1.7.0",
    "babel-preset-es2015": "^6.24.1",
    "babel-preset-stage-0": "^6.24.1",
    "cross-env": "^5.1.4",
    "css-loader": "^0.28.10",
    "es6-promise": "^4.2.4",
    "event-source-polyfill": "0.0.12",
    "extract-text-webpack-plugin": "^3.0.2",
    "file-loader": "^1.1.11",
    "gulp": "^3.9.1",
    "gulp-gzip": "^1.4.2",
    "gulp-oss": "^0.1.1",
    "html-webpack-plugin": "^3.0.6",
    "less": "^3.0.1",
    "less-loader": "^4.1.0",
    "postcss-import": "^11.1.0",
    "postcss-pxtorem": "^4.0.1",
    "rimraf": "^2.6.2",
    "style-loader": "^0.20.3",
    "uglifyjs-webpack-plugin": "^1.2.3",
    "vue-loader": "^14.2.1",
    "vue-style-loader": "^4.0.2",
    "vue-template-compiler": "^2.5.15",
    "vux-loader": "^1.2.8",
    "webpack": "^3.11.0",
    "webpack-bundle-analyzer": "^2.13.1",
    "webpack-dev-middleware": "^2.0.6",
    "webpack-dev-server": "^2.11.2",
    "webpack-hot-middleware": "^2.21.2"
  }

webpack.config.js

const path = require('path')
const webpack = require('webpack')
// const AssetsPlugin = require('assets-webpack-plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const ExtractTextPlugin = require('extract-text-webpack-plugin')
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
const CopyWebpackPlugin = require('copy-webpack-plugin')

const uglify = require('uglifyjs-webpack-plugin')
// const pageConfig = require('./src/entry.js')
const vuxLoader = require('vux-loader')
const envConfig = require('./server/config/index.' + process.env.ENV_CONFIG + '.js')

function resolve (dir) {
  return path.join(__dirname, './src/', dir)
}

let devEvn = process.env.NODE_ENV === 'development'

let entries = {
  'app': devEvn ? ['babel-polyfill', 'event-source-polyfill', resolve('app.js')] : [
    resolve('app.js')
  ]
}

// for(let key in pageConfig) {
//   let info = pageConfig[key]
//   entries[info.name] = devEvn ? ['webpack-hot-middleware/client?noInfo=true&reload=true', info.dist] : info.dist
// }

const webpackConfig = {
  // mode: process.env.NODE_ENV,
  entry: entries, 
  devtool: devEvn ? 'inline-source-map' : false,
  resolve: {
    extensions: [".js", ".vue", ".css", ".less"],
    alias: {
      'utils': resolve('utils'),
      'config': resolve('apiConfig.js'),
      'images': resolve('assets/img'),
      'components': resolve('components/common'),
    },
  },
  devServer: {
    // clientLogLevel: 'warning',
    historyApiFallback: true,
    disableHostCheck: true,
    // compress: true,
    host: '0.0.0.0',
    hot: true,
    port: 8087,
    contentBase: path.join(__dirname, "./src/assets"),
  },
  output: {
    path: path.resolve(__dirname, './dist'),
    publicPath: devEvn ? '/' : 'http://???/cdn/shopping-mall/release/',
    filename: '[name].[hash].js',
    chunkFilename: '[name].bundle.js',
  },
  module: {
    rules: [{
      test: /\.js$/,
      exclude: /(node_modules|bower_components)/,
      use: 'babel-loader'
    }, {
      test: /\.vue$/,
      loader: 'vue-loader',
      options: {
        loaders: {
          less: ['vue-style-loader', 'css-loader?minimize', 'less-loader'],
          css: ['vue-style-loader', 'css-loader?minimize'],
        },
        preserveWhitespace: false,
        postcss: [require('autoprefixer')({ browsers: ['last 7 versions'] })]
      }
    }, {
      test: /\.(less|css)$/,
      // use: ["style-loader", "css-loader", "less-loader"]
      use: devEvn ? ["style-loader", "css-loader", "less-loader"] : ExtractTextPlugin.extract({
        fallback: 'style-loader',
        use: ["css-loader", "less-loader"]
      })
    }, {
      test: /\.(png|jpg|jpeg|gif|svg|eot|ttf|woff|woff2)$/,
      use: ['file-loader?limit=1000&name=files/[md5:hash:base64:10].[ext]']
    }]
  },
  plugins: devEvn ? [
    new webpack.DefinePlugin({
      'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
      'process.env.config': JSON.stringify(envConfig.client)
    }),
    new webpack.HotModuleReplacementPlugin(),
    new webpack.NoEmitOnErrorsPlugin(),
    new HtmlWebpackPlugin({
      template: 'src/index.html'
    }),
    // new BundleAnalyzerPlugin()
  ] : [
    new webpack.DefinePlugin({
      'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
      'process.env.config': JSON.stringify(envConfig.client)
    }),
    new webpack.optimize.CommonsChunkPlugin({
      name: 'common' // 指定公共 bundle 的名称。
    }),
    new uglify(),
    new ExtractTextPlugin('[name].[hash].css', {
      allChunks: true
    }),
    new HtmlWebpackPlugin({
      template: 'src/index.html'
    }),
    new CopyWebpackPlugin([
      {
        from: path.resolve(__dirname, './src/assets/config/'),
        to: path.resolve(__dirname, './dist/config'),
        ignore: [path.resolve(__dirname, './src/assets/config/index.js')],
      },
    ]),
    // new BundleAnalyzerPlugin()
  ]
}

module.exports = vuxLoader.merge(webpackConfig, {
  plugins: ['vux-ui', {
    name: 'less-theme',
    path: 'src/assets/style/theme.less' // 相对项目根目录路径
  }]
})

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

何其悲哀 2022-09-19 02:39:51

uglifyjs 呗,找不到就全局搜索

浅笑轻吟梦一曲 2022-09-19 02:39:51

image.png
这个vux库导致的,引用后面少了;这个符号,导致格式化出错了,你可以检查下,没有用这个vux,格式化应该是正常的。

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文