Commit d1402a4a authored by 向偲彪's avatar 向偲彪 Committed by lgcareer
Browse files

Front-end compliance modification (#1545)

parent 86677dfd
Loading
Loading
Loading
Loading
+0 −115
Original line number Diff line number Diff line
/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

var fs = require('fs')
var path = require('path')
var request = require('request')
var cdnUrl = 'https://s1.analysys.cn/libs/??'
var version = '1.0.0'

// js集合
var jslibs = {
  'es5': [
    'es5-shim/4.5.7/es5-shim.min.js',
    'es5-shim/4.5.7/es5-sham.min.js'
  ],
  '3rd': [
    'vue/2.5.2/vue.js',
    'vue-router/2.7.0/vue-router.min.js',
    'vuex/3.0.0/vuex.min.js',
    'jquery/3.3.1/jquery.min.js',
    'lodash.js/4.17.5/lodash.min.js',
    'jqueryui/1.12.1/jquery-ui.min.js',
    'twitter-bootstrap/3.3.7/js/bootstrap.min.js',
    'jsPlumb/2.8.5/js/jsplumb.min.js',
    'clipboard.js/2.0.1/clipboard.min.js',
    'd3/3.3.6/d3.min.js',
    'echarts/4.1.0/echarts.min.js',
    'dayjs/1.7.8/dayjs.min.js',
    'codemirror/5.43.0/codemirror.min.js',
    'codemirror/5.43.0/mode/sql/sql.min.js',
    'codemirror/5.43.0/addon/hint/show-hint.min.js',
    'codemirror/5.43.0/addon/hint/sql-hint.min.js',
    'codemirror/5.43.0/mode/textile/textile.min.js',
    'codemirror/5.43.0/mode/shell/shell.min.js',
    'codemirror/5.43.0/mode/python/python.min.js',
    'codemirror/5.43.0/addon/hint/xml-hint.min.js',
    'codemirror/5.43.0/mode/xml/xml.min.js',
    'html2canvas/0.5.0-beta4/html2canvas.min.js',
    'canvg/1.5/canvg.min.js'
  ],
  'local': []
}

// css
csslibs = {
  'base': [
    'normalize/7.0.0/normalize.min.css',
    'twitter-bootstrap/3.3.7/css/bootstrap.min.css',
    '-/@analysys/reset.css@1.0.1',
    '-/@vue/animate.css@'
  ],
  '3rd': [
    'highlight.js/9.13.1/styles/vs.min.css',
    'jsPlumb/2.8.5/css/jsplumbtoolkit-defaults.min.css',
    'codemirror/5.43.0/codemirror.min.css',
    'codemirror/5.20.0/theme/mdn-like.min.css',
    'codemirror/5.43.0/addon/hint/show-hint.min.css'
  ]
}

// Create folder directory
var dirPath = path.resolve(__dirname, '..', 'src/combo/' + version)

if (!fs.existsSync(dirPath)) {
  fs.mkdirSync(dirPath)
  console.log('Folder created successfully')
} else {
  console.log('Folder already exists')
}

var jsKeys = Object.keys(jslibs)
var jsUrl = jsKeys.map(v => {
  return jslibs[v].join()
})

jsUrl.forEach((v, i) => {
  var url = cdnUrl + v
  console.log(url)
  var stream = fs.createWriteStream(path.join(dirPath, jsKeys[i] + '.js'), { encoding: 'utf-8' })
  request(url).pipe(stream).on('close', function (err) {
    if (!err) {
      console.log('file[' + version + '/' + jsKeys[i] + '.js' + ']Download completed')
    }
  })
})

var cssKeys = Object.keys(csslibs)
var cssUrl = cssKeys.map(v => {
  return csslibs[v].join()
})

cssUrl.forEach((v, i) => {
  var url = cdnUrl + v
  console.log(url)
  var stream = fs.createWriteStream(path.join(dirPath, cssKeys[i] + '.css'), { encoding: 'utf-8' })
  request(url).pipe(stream).on('close', function (err) {
    if (!err) {
      console.log('file[' + version + '/' + cssKeys[i] + '.css' + ']Download completed')
    }
  })
})
+47 −33
Original line number Diff line number Diff line
@@ -18,8 +18,9 @@
const path = require('path')
const glob = require('globby')
const webpack = require('webpack')
const VueLoaderPlugin = require('vue-loader/lib/plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const HtmlWebpackExtPlugin = require('html-webpack-ext-plugin')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const isProduction = process.env.NODE_ENV !== 'development'

const resolve = dir => path.join(__dirname, '..', dir)
@@ -106,7 +107,7 @@ const pages = glob.sync(['*/!(_*).html'], { cwd: viewDir }).map(p => {
  }
  return new HtmlWebpackPlugin({
    filename: newPagePath || path.join('view', p),
    template: `html-loader?min=false!${path.join(viewDir, p)}`,
    template: `${path.join('src/view', p)}`,
    cache: true,
    inject: true,
    chunks: chunks,
@@ -121,14 +122,15 @@ const baseConfig = {
    publicPath: '/',
    filename: 'js/[name].[chunkhash:7].js'
  },
  devServer: {
    historyApiFallback: true,
    hot: true,
    inline: true,
    progress: true
  },
  module: {
    rules: [
      {
        test: /\.vue$/,
        loader: 'vue-loader',
        options: {
          hotReload: !isProduction
        }
      },
      {
        test: /\.js$/,
        exclude: /(node_modules|bower_components)/,
@@ -142,10 +144,41 @@ const baseConfig = {
          }
        ]
      },
      {
        test: /\.(sa|sc|c)ss$/,
        use: [
          {
            loader: MiniCssExtractPlugin.loader,
            options: {
              hmr: !isProduction,
            },
          },
          'css-loader',
          {
            loader: 'postcss-loader',
            options: {
              plugins: (loader) => [
                require('autoprefixer')({
                  overrideBrowserslist: [
                    "Android 4.1",
                    "iOS 7.1",
                    "Chrome > 31",
                    "ff > 31",
                    "ie >= 8"
                  ]
                }),
                require('cssnano')
              ]
            }
          },
          'sass-loader'
        ]
      },
      {
        test: /\.(png|jpe?g|gif|svg|cur)(\?.*)?$/,
        loader: 'file-loader',
        options: {
          esModule: false,
          name: 'images/[name].[ext]?[hash]'
        }
      },
@@ -153,6 +186,7 @@ const baseConfig = {
        test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
        loader: 'url-loader',
        options: {
          esModule: false,
          limit: 10000,
          // publicPath: distDir,
          name: 'font/[name].[hash:7].[ext]'
@@ -168,38 +202,18 @@ const baseConfig = {
    ],
    alias: {
      '@': resolve('src/js'),
      '~': resolve('src/lib')
      '~': resolve('src/lib'),
      'jquery':'jquery/dist/jquery.min.js',
      'jquery-ui': 'jquery-ui'
    },
    extensions: ['.js', 'json', '.vue', '.scss']
  },
  externals: {
    'vue': 'Vue',
    'vuex': 'Vuex',
    'vue-router': 'VueRouter',
    'jquery': '$',
    'lodash': '_',
    'bootstrap': 'bootstrap',
    'd3': 'd3',
    'canvg': 'canvg',
    'html2canvas': 'html2canvas',
    './jsplumb': 'jsPlumb',
    './highlight.js': 'highlight.js',
    './clipboard': 'clipboard',
    './codemirror': 'CodeMirror'
  },
  plugins: [
    new webpack.ProvidePlugin({ vue: 'Vue', _: 'lodash' }),
    new VueLoaderPlugin(),
    new webpack.ProvidePlugin({ vue: 'Vue', _: 'lodash',jQuery:"jquery/dist/jquery.min.js",$:"jquery/dist/jquery.min.js" }),
    new webpack.DefinePlugin({
      PUBLIC_PATH: JSON.stringify(process.env.PUBLIC_PATH ? process.env.PUBLIC_PATH : '')
    }),
    new HtmlWebpackExtPlugin({
      cache: true,
      delimiter: '$',
      locals: {
        NODE_ENV:isProduction,
        PUBLIC_PATH: process.env.PUBLIC_PATH ? process.env.PUBLIC_PATH : ''
      }
    }),
    ...pages
  ]
}
+4 −69
Original line number Diff line number Diff line
@@ -17,7 +17,7 @@
const webpack = require('webpack')
const merge = require('webpack-merge')
const { assetsDir, baseConfig } = require('./config')
const ExtractTextPlugin = require('extract-text-webpack-plugin')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const ProgressPlugin = require('progress-bar-webpack-plugin')
const getEnv = require('env-parse').getEnv

@@ -26,70 +26,6 @@ const config = merge.smart(baseConfig, {
  output: {
    filename: 'js/[name].js'
  },
  module: {
    rules: [
      {
        test: /\.vue$/,
        loader: 'vue-loader',
        options: {
          hotReload: true // Open hot overload
        }
      },
      {
        test: /\.css$/,
        loader: ExtractTextPlugin.extract({
          use: [
            'css-loader',
            {
              loader: 'postcss-loader',
              options: {
                plugins: (loader) => [
                  require('autoprefixer')({
                    overrideBrowserslist: [
                      "Android 4.1",
                      "iOS 7.1",
                      "Chrome > 31",
                      "ff > 31",
                      "ie >= 8"
                    ]              
                  }),
                  require('cssnano')
                ]
              }
            }
          ],
          fallback: ['vue-style-loader']
        })
      },
      {
        test: /\.scss$/,
        loader: ExtractTextPlugin.extract({
          use: [
            'css-loader',
            'sass-loader',
            {
              loader: 'postcss-loader',
              options: {
                plugins: (loader) => [
                  require('autoprefixer')({
                    overrideBrowserslist: [
                      "Android 4.1",
                      "iOS 7.1",
                      "Chrome > 31",
                      "ff > 31",
                      "ie >= 8"
                    ] 
                  }),
                  require('cssnano')
                ]
              }
            }
          ],
          fallback: ['vue-style-loader']
        })
      }
    ]
  },
  devServer: {
    hot: true,
    contentBase: assetsDir,
@@ -116,10 +52,9 @@ const config = merge.smart(baseConfig, {
  plugins: [
    new ProgressPlugin(),
    new webpack.HotModuleReplacementPlugin(),
    new ExtractTextPlugin({ filename: 'css/[name].css', allChunks: true }),
    new webpack.optimize.CommonsChunkPlugin({ name: 'common', filename: 'js/[name].js' }),
    new webpack.optimize.OccurrenceOrderPlugin()
  ]
    new MiniCssExtractPlugin({ filename: 'css/[name].css' })
  ],
  mode: 'development'
})

module.exports = config
+31 −99
Original line number Diff line number Diff line
@@ -19,10 +19,9 @@ const webpack = require('webpack')
const merge = require('webpack-merge')
const CopyWebpackPlugin = require('copy-webpack-plugin')
const { baseConfig } = require('./config')
const ExtractTextPlugin = require('extract-text-webpack-plugin')
const TerserPlugin = require('terser-webpack-plugin')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const ProgressPlugin = require('progress-bar-webpack-plugin')
const UglifyJSPlugin = require('uglifyjs-webpack-plugin')
const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin')

const resolve = dir =>
  path.resolve(__dirname, '..', dir)
@@ -32,105 +31,11 @@ const config = merge.smart(baseConfig, {
  output: {
    filename: 'js/[name].[chunkhash:7].js'
  },
  module: {
    rules: [
      {
        test: /\.vue$/,
        loader: 'vue-loader',
        options: {
          hotReload: false // Open hot overload
        }
      },
      {
        test: /\.css$/,
        loader: ExtractTextPlugin.extract({
          use: [
            'css-loader',
            {
              loader: 'postcss-loader',
              options: {
                plugins: (loader) => [
                  require('autoprefixer')({
                    overrideBrowserslist: [
                      "Android 4.1",
                      "iOS 7.1",
                      "Chrome > 31",
                      "ff > 31",
                      "ie >= 8"
                    ]      
                  }),
                  require('cssnano')
                ]
              }
            }
          ],
          fallback: ['vue-style-loader']
        })
      },
      {
        test: /\.scss$/,
        loader: ExtractTextPlugin.extract({
          use: [
            'css-loader',
            'sass-loader',
            {
              loader: 'postcss-loader',
              options: {
                plugins: (loader) => [
                  require('autoprefixer')({
                    overrideBrowserslist: [
                      "Android 4.1",
                      "iOS 7.1",
                      "Chrome > 31",
                      "ff > 31",
                      "ie >= 8"
                    ]
                  }),
                  require('cssnano')
                ]
              }
            }
          ],
          fallback: ['vue-style-loader']
        })
      }
    ]
  },
  plugins: [
    new ProgressPlugin(),
    new ExtractTextPlugin({ filename: 'css/[name].[contenthash:7].css', allChunks: true }),
    new webpack.optimize.CommonsChunkPlugin({ name: 'common', filename: 'js/[name].[hash:7].js' }),
    new MiniCssExtractPlugin({ filename: 'css/[name].[contenthash:7].css' }),
    new webpack.optimize.OccurrenceOrderPlugin(),
    new OptimizeCssAssetsPlugin({
      assetNameRegExp: /\.css$/g,
      cssProcessor: require('cssnano'),
      cssProcessorOptions: { discardComments: { removeAll: true } },
      canPrint: true
    }),
    new UglifyJSPlugin({
      parallel: true,
      sourceMap: true,
      uglifyOptions: {
        compress: {
          warnings: false,
          drop_debugger: true,
          drop_console: true,
          pure_funcs: ['console.log']// remove console
        },
        comments: function (n, c) {
          /*! IMPORTANT: Please preserve 3rd-party library license info, inspired from @allex/amd-build-worker/config/jsplumb.js */
          var text = c.value, type = c.type
          if (type === 'comment2') {
            return /^!|@preserve|@license|@cc_on|MIT/i.test(text)
          }
        }
      }
    }),
    new CopyWebpackPlugin([
      {
        from: resolve('src/combo'),
        to: resolve('dist/combo')
      },
      {
        from: resolve('src/lib'),
        to: resolve('dist/lib')
@@ -140,7 +45,34 @@ const config = merge.smart(baseConfig, {
        to: resolve('dist/images')
      },
    ]),
  ]
  ],
  optimization: {
    minimize: true,
    minimizer: [
      new TerserPlugin({
        terserOptions: {
          compress: {
            warnings: false,
            drop_console: true,
            drop_debugger: true,
            pure_funcs: ['console.log']
          }
        },
        cache: true,
        parallel: true,
        sourceMap: false,
        exclude: /node_modules/,
        extractComments: (astNode, comment) => {
          if (/^!|@preserve|@license|@cc_on|MIT/i.test(comment.value)) {
            return true
          }
          return false
        }
      }),
    ],
    sideEffects: true
  },
  mode: 'production'
})

module.exports = config
Loading