代码拉取完成,页面将自动刷新
const path = require('path')
const webpack = require('webpack')
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const autoprefixer = require('autoprefixer');
const pxtorem = require('postcss-pxtorem');
const HtmlWebpackPlugin = require('html-webpack-plugin'); // 通过 npm 安装
const Visualizer = require('webpack-visualizer-plugin'); // remove it in production environment.
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin; // remove it in production environment.
const otherPlugins = process.argv[1].indexOf('webpack-dev-server') >= 0 ? [] : [
new Visualizer(), // remove it in production environment.
new BundleAnalyzerPlugin({
defaultSizes: 'parsed',
// generateStatsFile: true,
statsOptions: { source: false }
}), // remove it in production environment.
];
const postcssOpts = {
ident: 'postcss', // https://webpack.js.org/guides/migrating/#complex-options
plugins: () => [
autoprefixer({
browsers: ['last 2 versions', 'Firefox ESR', '> 1%', 'ie >= 8', 'iOS >= 8', 'Android >= 4'],
}),
// pxtorem({ rootValue: 100, propWhiteList: [] })
],
};
module.exports = {
devtool: 'source-map', // or 'inline-source-map'
devServer: {
disableHostCheck: true,
host: '0.0.0.0',
proxy: {
'/app/**': {
contentBase: path.join(__dirname, '.'),
target: "http://app.7zhanglao.vip/app/",
// target: "http://localhost:8762/app/",
changeOrigin:true,
pathRewrite: {'^/app': ''},
}
}
},
entry: { "index": path.resolve(__dirname, 'src/index.js') },
output: {
filename: '[name].js',
chunkFilename: '[id].chunk.js',
path: path.join(__dirname, 'dist'),
publicPath: './'
},
resolve: {
modules: [path.resolve(__dirname, 'node_modules'), path.join(__dirname, 'src')],
extensions: ['.web.js', '.jsx', '.js', '.json'],
},
module: {
rules: [
{
test: /\.(js|jsx)$/, exclude: /node_modules/, loader: 'babel-loader',
options: {
plugins: [
'external-helpers', // why not work?
["transform-runtime", { polyfill: false }],
["import", [{ "style": "css", "libraryName": "antd-mobile" }]]
],
presets: ['es2015', 'stage-0', 'react']
// presets: [['es2015', { modules: false }], 'stage-0', 'react'] // tree-shaking
}
},
{ test: /\.(jpg|png)$/, loader: "url-loader?limit=8192" },
// 注意:如下不使用 ExtractTextPlugin 的写法,不能单独 build 出 css 文件
// { test: /\.less$/i, loaders: ['style-loader', 'css-loader', 'less-loader'] },
// { test: /\.css$/i, loaders: ['style-loader', 'css-loader'] },
{
test: /\.less$/i, use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: [
'css-loader', { loader: 'postcss-loader', options: postcssOpts }, 'less-loader'
]
})
},
{
test: /\.css$/i, use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: [
'css-loader', { loader: 'postcss-loader', options: postcssOpts }
]
})
}
]
},
externals: {
"react": "React",
"react-dom": "ReactDOM"
},
plugins: [
new webpack.optimize.ModuleConcatenationPlugin(),
// new webpack.optimize.CommonsChunkPlugin('shared.js'),
new webpack.optimize.CommonsChunkPlugin({
// minChunks: 2,
name: 'shared',
filename: 'shared.js'
}),
new HtmlWebpackPlugin({template: './index.html'}),
new ExtractTextPlugin({ filename: '[name].css', allChunks: true }),
...otherPlugins
]
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。