123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143 |
- const webpack = require('webpack');
- const autoprefixer = require('autoprefixer');
- const path = require('path');
- const CleanWebpackPlugin = require('clean-webpack-plugin');
- const HtmlWebpackPlugin = require('html-webpack-plugin');
- const GLOBALS = {
- 'process.env': {NODE_ENV: '"production"',API_ROOT:'"/re"'}
- };
- let OUTPUT_PATH = 'dist/';
- let PUBLIC_PATH = '';
- if (process.env.EXTERNAL) {
- OUTPUT_PATH = 'build-external/';
- // Change this line to point to resources on an external host.
- PUBLIC_PATH = 'https://s3.amazonaws.com/static.weave.works/scope-ui/';
- }
- /**
- * This is the Webpack configuration file for production.
- */
- module.exports = {
- // fail on first error when building release
- bail: true,
- cache: {},
- entry: {
- app: './app/scripts/main',
- 'terminal-app': './app/scripts/terminal-main',
- // keep only some in here, to make vendors and app bundles roughly same size
- vendors: ['@babel/polyfill', 'classnames', 'immutable',
- 'react', 'react-dom', 'react-redux', 'redux', 'redux-thunk'
- ]
- },
- // See https://webpack.js.org/concepts/mode/#mode-production.
- mode: 'production',
- output: {
- filename: '[name]-[chunkhash].js',
- path: path.join(__dirname, OUTPUT_PATH),
- publicPath: PUBLIC_PATH,
- },
- plugins: [
- new CleanWebpackPlugin([OUTPUT_PATH]),
- new webpack.DefinePlugin(GLOBALS),
- new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
- new webpack.IgnorePlugin(/.*\.map$/, /xterm\/lib\/addons/),
- new HtmlWebpackPlugin({
- chunks: ['vendors', 'terminal-app'],
- filename: 'terminal.html',
- hash: true,
- template: 'app/html/index.html',
- }),
- new HtmlWebpackPlugin({
- chunks: ['vendors', 'app'],
- filename: 'index.html',
- hash: true,
- template: 'app/html/index.html',
- }),
- ],
- module: {
- // Webpack is opionated about how pkgs should be laid out:
- // https://github.com/webpack/webpack/issues/1617
- noParse: [/xterm\/dist\/xterm\.js/],
- rules: [
- {
- test: /\.js$/,
- exclude: /node_modules|vendor/,
- // loader: 'eslint-loader',
- use:[
- // {loader:"eslint-loader"},
- {
- loader:"babel-loader",
- options:{//options、query不能和loader数组一起使用
- cacheDirectory:true//利用缓存,提高性能,babel is slow
- },
- }
- ],
- enforce: 'pre',
- // options: {
- // failOnError: true
- // }
- },
- {
- test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/,
- loader: 'url-loader',
- options: {
- limit: 10000,
- minetype: 'application/font-woff',
- }
- },
- {
- test: /\.(ttf|eot|svg|ico)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
- loader: 'file-loader'
- },
- {
- test: /\.ico$/,
- loader: 'file-loader',
- options: {
- name: '[name].[ext]'
- }
- },
- {
- test: /\.jsx?$/,
- exclude: /node_modules|vendor/,
- loader: 'babel-loader'
- },
- {
- test: /\.(css|less)$/,
- use: [
- { loader: 'style-loader' },
- { loader: 'css-loader' },
- { loader: 'less-loader' },
- {
- loader: 'postcss-loader',
- options: {
- plugins: [
- autoprefixer({
- browsers: ['last 2 versions']
- })
- ]
- }
- },
- ],
- }
- ]
- },
- resolve: {
- extensions: ['.js', '.jsx']
- },
- };
|