2017-07-05 21:08:51 +08:00
|
|
|
|
var path = require('path');
|
2017-07-25 14:18:57 +08:00
|
|
|
|
var AssetsPlugin = require('assets-webpack-plugin')
|
2017-09-03 08:43:13 +08:00
|
|
|
|
var CompressionPlugin = require('compression-webpack-plugin')
|
2017-11-27 20:11:28 +08:00
|
|
|
|
var commonLib = require('./common/plugin.js');
|
2017-07-25 14:18:57 +08:00
|
|
|
|
var assetsPluginInstance = new AssetsPlugin({
|
2017-07-25 15:07:55 +08:00
|
|
|
|
filename: 'static/prd/assets.js',
|
|
|
|
|
processOutput: function (assets) {
|
|
|
|
|
return 'window.WEBPACK_ASSETS = ' + JSON.stringify(assets);
|
|
|
|
|
}
|
2017-09-06 10:18:13 +08:00
|
|
|
|
})
|
2017-11-27 20:11:28 +08:00
|
|
|
|
var fs = require('fs');
|
2017-10-05 09:12:44 +08:00
|
|
|
|
|
2017-09-06 10:18:13 +08:00
|
|
|
|
|
|
|
|
|
var compressPlugin = new CompressionPlugin({
|
|
|
|
|
asset: "[path].gz[query]",
|
|
|
|
|
algorithm: "gzip",
|
|
|
|
|
test: /\.(js|css)$/,
|
|
|
|
|
threshold: 10240,
|
2017-09-08 11:18:30 +08:00
|
|
|
|
minRatio: 0.8
|
2017-09-05 10:24:13 +08:00
|
|
|
|
});
|
|
|
|
|
|
2017-10-05 09:12:44 +08:00
|
|
|
|
function createScript(plugin, pathAlias){
|
|
|
|
|
let options = plugin.options ? JSON.stringify(plugin.options) : null
|
|
|
|
|
return `"${plugin.name}" : {module: require('${pathAlias}/yapi-plugin-${plugin.name}/client.js'),options: ${options}}`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function initPlugins(configPlugin){
|
2017-11-27 20:11:28 +08:00
|
|
|
|
configPlugin = require('../config.json').plugins;
|
2017-10-05 09:12:44 +08:00
|
|
|
|
var systemConfigPlugin = require('./common/config.js').exts;
|
|
|
|
|
|
2017-09-28 20:26:54 +08:00
|
|
|
|
var scripts = [] ;
|
2017-10-05 09:12:44 +08:00
|
|
|
|
if(configPlugin && Array.isArray(configPlugin) && configPlugin.length){
|
|
|
|
|
configPlugin = commonLib.initPlugins(configPlugin, 'plugin');
|
|
|
|
|
configPlugin.forEach((plugin)=>{
|
|
|
|
|
if(plugin.client && plugin.enable){
|
|
|
|
|
scripts.push(createScript(plugin, 'plugins'))
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-05 10:24:13 +08:00
|
|
|
|
})
|
2017-10-05 09:12:44 +08:00
|
|
|
|
|
2017-09-05 10:24:13 +08:00
|
|
|
|
}
|
2017-10-05 09:12:44 +08:00
|
|
|
|
|
|
|
|
|
systemConfigPlugin = commonLib.initPlugins(systemConfigPlugin, 'ext');
|
|
|
|
|
systemConfigPlugin.forEach(plugin=>{
|
|
|
|
|
if(plugin.client && plugin.enable){
|
|
|
|
|
scripts.push(createScript(plugin, 'exts'))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
scripts = "module.exports = {" + scripts.join(",") + "}";
|
|
|
|
|
fs.writeFileSync('client/plugin-module.js', scripts);
|
2017-09-05 10:24:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
initPlugins();
|
2017-08-10 21:20:57 +08:00
|
|
|
|
|
2017-07-05 19:31:50 +08:00
|
|
|
|
module.exports = {
|
2017-09-06 10:18:13 +08:00
|
|
|
|
plugins: [{
|
|
|
|
|
name: 'antd',
|
|
|
|
|
options: {
|
|
|
|
|
modifyQuery: function (defaultQuery) { // 可查看和编辑 defaultQuery
|
|
|
|
|
defaultQuery.plugins = [];
|
|
|
|
|
defaultQuery.plugins.push(["transform-runtime", {
|
|
|
|
|
"polyfill": false,
|
|
|
|
|
"regenerator": true
|
|
|
|
|
}]);
|
|
|
|
|
defaultQuery.plugins.push('transform-decorators-legacy');
|
|
|
|
|
defaultQuery.plugins.push(["import", { libraryName: "antd"}])
|
|
|
|
|
return defaultQuery;
|
|
|
|
|
},
|
2017-09-28 20:26:54 +08:00
|
|
|
|
exclude: /node_modules\/(?!yapi-plugin)/
|
|
|
|
|
}
|
2017-12-08 15:21:56 +08:00
|
|
|
|
}],
|
2017-07-14 12:18:55 +08:00
|
|
|
|
// devtool: 'cheap-source-map',
|
2017-07-25 15:07:55 +08:00
|
|
|
|
config: function (ykit) {
|
2017-07-25 14:18:57 +08:00
|
|
|
|
return {
|
2017-09-28 20:26:54 +08:00
|
|
|
|
exports: [
|
2017-07-25 15:07:55 +08:00
|
|
|
|
'./index.js'
|
|
|
|
|
],
|
2017-09-13 17:35:56 +08:00
|
|
|
|
commonsChunk: {
|
|
|
|
|
vendors: {
|
2018-01-11 10:45:44 +08:00
|
|
|
|
lib: [
|
2018-02-02 11:07:29 +08:00
|
|
|
|
// 'anujs',
|
|
|
|
|
'react',
|
|
|
|
|
'react-dom',
|
2018-01-11 10:45:44 +08:00
|
|
|
|
'redux',
|
2017-09-13 17:35:56 +08:00
|
|
|
|
'redux-thunk',
|
|
|
|
|
'redux-promise',
|
|
|
|
|
'react-router',
|
|
|
|
|
'react-router-dom',
|
2017-12-08 18:07:06 +08:00
|
|
|
|
'prop-types',
|
2017-09-21 09:17:41 +08:00
|
|
|
|
'react-dnd-html5-backend',
|
|
|
|
|
'react-dnd',
|
|
|
|
|
'reactabular-table',
|
|
|
|
|
'reactabular-dnd',
|
2017-12-08 18:07:06 +08:00
|
|
|
|
'table-resolver',
|
|
|
|
|
'recharts'
|
2017-09-13 17:35:56 +08:00
|
|
|
|
],
|
|
|
|
|
lib2: [
|
|
|
|
|
'brace',
|
|
|
|
|
'mockjs',
|
2017-09-21 09:17:41 +08:00
|
|
|
|
'json5',
|
2017-12-08 18:07:06 +08:00
|
|
|
|
'url',
|
|
|
|
|
'wangeditor',
|
|
|
|
|
'axios',
|
|
|
|
|
'moment'
|
2017-09-13 17:35:56 +08:00
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
},
|
2017-09-08 11:18:30 +08:00
|
|
|
|
modifyWebpackConfig: function (baseConfig) {
|
2017-08-31 18:04:45 +08:00
|
|
|
|
|
2017-08-08 14:25:33 +08:00
|
|
|
|
var ENV_PARAMS = {};
|
|
|
|
|
switch (this.env) {
|
|
|
|
|
case 'local':
|
2017-08-23 20:41:47 +08:00
|
|
|
|
ENV_PARAMS = 'dev';
|
2017-08-08 14:25:33 +08:00
|
|
|
|
break;
|
|
|
|
|
case 'dev':
|
2017-08-23 20:41:47 +08:00
|
|
|
|
ENV_PARAMS = 'dev';
|
2017-08-08 14:25:33 +08:00
|
|
|
|
break;
|
|
|
|
|
case 'prd':
|
2017-08-23 20:41:47 +08:00
|
|
|
|
ENV_PARAMS = 'production';
|
2017-08-08 14:25:33 +08:00
|
|
|
|
break;
|
|
|
|
|
default:
|
2017-08-22 10:43:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-08-08 14:25:33 +08:00
|
|
|
|
baseConfig.plugins.push(new this.webpack.DefinePlugin({
|
2017-10-05 09:12:44 +08:00
|
|
|
|
'process.env.NODE_ENV': JSON.stringify(ENV_PARAMS)
|
2017-08-08 14:25:33 +08:00
|
|
|
|
}))
|
2017-08-10 21:20:57 +08:00
|
|
|
|
|
|
|
|
|
//初始化配置
|
2017-07-25 15:07:55 +08:00
|
|
|
|
baseConfig.devtool = 'cheap-module-eval-source-map'
|
2017-08-31 18:04:45 +08:00
|
|
|
|
baseConfig.context = path.resolve(__dirname, './client');
|
2017-09-15 12:01:17 +08:00
|
|
|
|
baseConfig.resolve.alias.client = '/client';
|
2017-08-31 18:04:45 +08:00
|
|
|
|
baseConfig.resolve.alias.common = '/common';
|
2017-09-28 20:26:54 +08:00
|
|
|
|
baseConfig.resolve.alias.plugins = '/node_modules';
|
2017-09-15 12:01:17 +08:00
|
|
|
|
baseConfig.resolve.alias.exts = '/exts';
|
2018-01-11 10:45:44 +08:00
|
|
|
|
|
2018-02-14 11:13:51 +08:00
|
|
|
|
// baseConfig.resolve.alias.react = 'anujs';
|
|
|
|
|
// baseConfig.resolve.alias['react-dom'] = 'anujs';
|
2018-01-11 10:45:44 +08:00
|
|
|
|
|
2017-07-25 15:07:55 +08:00
|
|
|
|
baseConfig.output.prd.path = 'static/prd';
|
|
|
|
|
baseConfig.output.prd.publicPath = '';
|
2017-07-25 16:24:56 +08:00
|
|
|
|
baseConfig.output.prd.filename = '[name]@[chunkhash][ext]'
|
2017-08-10 21:20:57 +08:00
|
|
|
|
|
2017-12-12 20:52:00 +08:00
|
|
|
|
baseConfig.module.noParse = /node_modules\/jsondiffpatch\/public\/build\/.*js/,
|
2017-09-13 17:35:56 +08:00
|
|
|
|
|
2017-08-22 10:43:40 +08:00
|
|
|
|
baseConfig.module.loaders.push({
|
|
|
|
|
test: /\.less$/,
|
|
|
|
|
loader: ykit.ExtractTextPlugin.extract(
|
|
|
|
|
require.resolve('style-loader'),
|
|
|
|
|
require.resolve('css-loader')
|
|
|
|
|
+ '?sourceMap!'
|
|
|
|
|
+ require.resolve('less-loader') + '?sourceMap'
|
|
|
|
|
)
|
|
|
|
|
})
|
2017-07-25 15:07:55 +08:00
|
|
|
|
baseConfig.module.loaders.push({
|
|
|
|
|
test: /\.(sass|scss)$/,
|
|
|
|
|
loader: ykit.ExtractTextPlugin.extract(
|
|
|
|
|
require.resolve('css-loader')
|
|
|
|
|
+ '?sourceMap!'
|
2017-09-07 10:40:58 +08:00
|
|
|
|
+ require.resolve('fast-sass-loader-china') + '?sourceMap'
|
2017-07-25 15:07:55 +08:00
|
|
|
|
)
|
|
|
|
|
})
|
|
|
|
|
baseConfig.module.preLoaders.push({
|
2017-07-25 17:06:49 +08:00
|
|
|
|
test: /\.(js|jsx)$/,
|
2017-12-12 20:52:00 +08:00
|
|
|
|
exclude: /node_modules|google-diff.js/,
|
2017-09-06 10:18:13 +08:00
|
|
|
|
loader: "eslint-loader"
|
2017-07-25 15:07:55 +08:00
|
|
|
|
});
|
2017-07-25 14:18:57 +08:00
|
|
|
|
|
2017-07-25 17:06:49 +08:00
|
|
|
|
if (this.env == 'prd') {
|
2017-10-13 11:44:16 +08:00
|
|
|
|
baseConfig.plugins.push(new this.webpack.optimize.UglifyJsPlugin({
|
|
|
|
|
compress: {
|
|
|
|
|
warnings: false
|
|
|
|
|
}
|
|
|
|
|
}))
|
2017-07-25 17:06:49 +08:00
|
|
|
|
baseConfig.plugins.push(assetsPluginInstance)
|
2017-09-03 08:43:13 +08:00
|
|
|
|
baseConfig.plugins.push(compressPlugin)
|
|
|
|
|
|
2017-07-25 17:06:49 +08:00
|
|
|
|
}
|
2017-07-25 15:07:55 +08:00
|
|
|
|
return baseConfig;
|
|
|
|
|
}
|
2017-07-06 14:25:52 +08:00
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
server: {
|
|
|
|
|
// true/false,默认 false,效果相当于 ykit server --hot
|
2017-09-06 10:18:13 +08:00
|
|
|
|
hot: true,
|
2017-07-06 14:25:52 +08:00
|
|
|
|
// true/false,默认 false,开启后可在当前打开的页面提示打包错误
|
2017-09-06 10:18:13 +08:00
|
|
|
|
overlay: false
|
2017-07-06 14:25:52 +08:00
|
|
|
|
},
|
|
|
|
|
hooks: {},
|
|
|
|
|
commands: []
|
2017-09-08 11:18:30 +08:00
|
|
|
|
};
|