1 Star 0 Fork 0

exrick / native-ui

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
webpack.config.product.js 2.97 KB
一键复制 编辑 原始数据 按行查看 历史
exrick 提交于 2019-02-08 15:24 . 提交原始代码
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;
JavaScript
1
https://gitee.com/ericktse/native-ui.git
git@gitee.com:ericktse/native-ui.git
ericktse
native-ui
native-ui
master

搜索帮助