5 Star 10 Fork 2

wmdz / react-weui-scaffold

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
webpack.config.doc.js 4.91 KB
一键复制 编辑 原始数据 按行查看 历史
wwmmddz@sina.com 提交于 2018-03-17 16:31 . commit
const webpack = require('webpack');
const path = require('path');
const autoprefixer = require('autoprefixer');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const nodeEnv = process.env.NODE_ENV || 'development';
const isProduction = process.argv.indexOf('-p') !== -1;
//const isProduction = nodeEnv === 'production';
const jsSourcePath = path.join(__dirname, 'docs');
const buildPath = path.join(__dirname, 'build/demo/docs');
const sourcePath = path.join(__dirname, 'docs');
// Common plugins
const plugins = [
new webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
filename: 'vendor-[hash].js',
minChunks(module) {
const context = module.context;
return context && context.indexOf('node_modules') >= 0;
},
}),
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify(isProduction ? 'production' : 'development'),
},
}),
new webpack.NamedModulesPlugin(),
new HtmlWebpackPlugin({
template: path.join(sourcePath, 'index.html'),
path: buildPath,
filename: 'index.html',
})
];
// Common rules
const rules = [
{
test: /\.(js|jsx)$/,
oneOf: [
{
include: [path.resolve(__dirname, 'docs'), path.resolve(__dirname, 'example')],
exclude: [/node_modules/, path.resolve(__dirname, 'src')],
use: [
'babel-loader',
]
},
{
include: path.resolve(__dirname, 'src'),
exclude: [/node_modules/, path.resolve(__dirname, 'docs')],
use: [
'raw-loader',
]
},
],
}, {
test: /\.css/,
loader: [
'style-loader',
{ loader: 'css-loader', options: { sourceMap: !isProduction, importLoaders: 1 } },
{
loader: 'postcss-loader',
options: {
sourceMap: !isProduction,
plugins: (loader) => [
autoprefixer({
browsers: [
'last 3 version',
'ie >= 10',
],
})
]
}
}]
}, {
test: /\.less$/,
exclude: /node_modules/,
use: [
'style-loader',
// Using source maps breaks urls in the CSS loader
// https://github.com/webpack/css-loader/issues/232
// This comment solves it, but breaks testing from a local network
// https://github.com/webpack/css-loader/issues/232#issuecomment-240449998
// 'css-loader?sourceMap',
{ loader: 'css-loader', options: { sourceMap: !isProduction, importLoaders: 2 } },
{
loader: 'postcss-loader',
options: {
sourceMap: !isProduction,
plugins: (loader) => [
autoprefixer({
browsers: [
'last 3 version',
'ie >= 10',
],
})
]
}
},
{
loader: 'less-loader',
options: {
sourceMap: !isProduction
}
}
],
},
{
test: /\.(png|gif|jpg|svg)$/,
use: 'url-loader?limit=20480&name=assets/[name]-[hash].[ext]',
}
];
if (!isProduction) {
plugins.push(
new webpack.HotModuleReplacementPlugin()
);
} else {
plugins.push(
new webpack.optimize.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,
},
})
);
}
module.exports = {
devtool: isProduction ? false : 'source-map',
context: jsSourcePath,
entry: {
js: './app.js',
},
output: {
path: buildPath,
publicPath: '',
filename: 'app-[hash].js',
},
module: {
rules,
},
resolve: {
extensions: ['.webpack-loader.js', '.web-loader.js', '.loader.js', '.js', '.jsx', '.less'],
modules: [
path.resolve(__dirname, 'node_modules'),
jsSourcePath,
],
},
plugins,
devServer: {
contentBase: isProduction ? buildPath : sourcePath,
historyApiFallback: true,
port: 3000,
compress: isProduction,
inline: !isProduction,
hot: !isProduction,
host: '0.0.0.0',
disableHostCheck: true,
stats: {
assets: true,
children: false,
chunks: false,
hash: false,
modules: false,
publicPath: false,
timings: true,
version: false,
warnings: true,
colors: {
green: '\u001b[32m',
},
},
},
};
JavaScript
1
https://gitee.com/wmdzkey/react-weui-scaffold.git
git@gitee.com:wmdzkey/react-weui-scaffold.git
wmdzkey
react-weui-scaffold
react-weui-scaffold
master

搜索帮助