代码拉取完成,页面将自动刷新
var path = require('path');
var glob = require('glob');
var node_modules_dir = path.join(__dirname,'node_modules');
var webpack = require('webpack');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var HtmlWebpackPlugin = require('html-webpack-plugin');
var CopyWebpackPlugin = require('copy-webpack-plugin');
var CommonsChunkPlugin = webpack.optimize.CommonsChunkPlugin;
var UglifyJsPlugin = webpack.optimize.UglifyJsPlugin;
const SOURCE_DIR = 'product/src/';
const PRODUCT_DIR = 'product';
//var Dev = require('ucsmy-dev');
//var ucsmy_dev = new Dev({port:10081});
//process.env.NODE_ENV = 'production';
const debug = process.env.NODE_ENV !== 'production';
var entries = getEntrys(SOURCE_DIR+'*/*.*');
var chunks = Object.keys(entries.js);
var pages = Object.keys(entries.pages);
var resourcs = Object.keys(entries.resource);
var copyfile_configs = [];
var config = {
entry: entries.js,
output: {
path: path.join(__dirname, PRODUCT_DIR),
filename: '[name]',
},
module: {
loaders: [{
test: /\.eot|ttf|svg|png|gif|woff2?$/,
exclude: /node_modules/,
loader: 'url',
query: {
limit: 10240,
name: 'images/[name].[ext]'
}
},
{
test: /\.js?$/, // Match both .js and .jsx files
exclude: /node_modules/,
loader: "jsx-loader",
},
],
},
plugins:[
debug ? function() {} : new UglifyJsPlugin({ //压缩代码
compress: {
warnings: false
},
output:{
comments:false,
},
except: ['$super', '$', 'exports', 'require'] //排除关键字
}),
],
}
resourcs.forEach(function(pathname){
var copy_conf ={
from:SOURCE_DIR+pathname,
to:pathname,
}
copyfile_configs.push(copy_conf);
});
config.plugins.push(new CopyWebpackPlugin(copyfile_configs));
pages.forEach(function(pathname){
if(pathname.indexOf('.html')===pathname.length-5){
var html_conf ={
filename:pathname,
template:SOURCE_DIR+pathname,
inject:'body',
chunks:[pathname.substring(0,pathname.length-5)+'.js'],
hash:false,
minify:{
removeComments: true,
collapseWhitespace:false
}
}
config.plugins.push(new HtmlWebpackPlugin(html_conf));
}
});
function getEntrys(globPath) {
var files = glob.sync(globPath);
var entries = {js:{},pages:{},resource:{}},entry, dirname, basename, pathname, extname;
for (var i = 0; i < files.length; i++) {
entry = files[i];
dirname = path.dirname(entry);
extname = path.extname(entry);
basename = path.basename(entry, extname);
var split = dirname.split('/');
pathname = path.join(split.slice(2,split.length).join("/"), basename+extname);
if(extname==='.js'){
entries.js[pathname]="./"+entry;
}else if(extname==='.html'){
entries.pages[pathname]="./"+entry;
}else{
entries.resource[pathname]="./"+entry;
}
}
// console.log(entries);
return entries;
}
module.exports = config;
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。