yapi/ykit.js

100 lines
2.9 KiB
JavaScript
Raw Normal View History

2017-07-05 21:08:51 +08:00
var path = require('path');
var AssetsPlugin = require('assets-webpack-plugin')
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-07-05 19:31:50 +08:00
module.exports = {
2017-07-10 21:29:03 +08:00
plugins: [{
2017-07-11 10:22:06 +08:00
name: 'antd',
options: {
modifyQuery: function (defaultQuery) { // 可查看和编辑 defaultQuery
2017-08-07 19:34:34 +08:00
defaultQuery.plugins = [];
2017-08-09 11:54:40 +08:00
defaultQuery.plugins.push(["transform-runtime", {
"polyfill": false,
"regenerator": true
}]);
2017-07-11 10:22:06 +08:00
defaultQuery.plugins.push('transform-decorators-legacy');
defaultQuery.plugins.push(["import", { libraryName: "antd", style: "css" }])
2017-07-11 10:22:06 +08:00
return defaultQuery;
}
}
}],
2017-07-14 12:18:55 +08:00
// devtool: 'cheap-source-map',
2017-07-25 15:07:55 +08:00
config: function (ykit) {
return {
2017-07-25 15:07:55 +08:00
exports: [
'./index.js'
],
commonsChunk: {
//filename: 'scripts/[name]@[chunkhash][ext]',
vendors: {
lib: ['react', 'redux',
'redux-thunk',
'react-dom',
'redux-promise',
'react-router-dom',
2017-08-08 19:24:01 +08:00
'prop-types'
2017-08-09 11:54:40 +08:00
2017-08-08 19:24:01 +08:00
],
lib2:[
'axios',
'moment'
]
}
},
2017-07-25 15:07:55 +08:00
modifyWebpackConfig: function (baseConfig) {
var ENV_PARAMS = {};
switch (this.env) {
case 'local':
ENV_PARAMS = {development: true};
break;
case 'dev':
ENV_PARAMS = {development: true};
break;
case 'prd':
ENV_PARAMS = {development: false};
break;
default:
}
baseConfig.plugins.push(new this.webpack.DefinePlugin({
ENV_PARAMS: JSON.stringify(ENV_PARAMS)
}))
2017-07-25 15:07:55 +08:00
baseConfig.devtool = 'cheap-module-eval-source-map'
baseConfig.context = path.resolve(__dirname, "client");
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-07-25 15:07:55 +08:00
baseConfig.module.loaders.push({
test: /\.(sass|scss)$/,
loader: ykit.ExtractTextPlugin.extract(
require.resolve('css-loader')
+ '?sourceMap!'
+ require.resolve('fast-sass-loader') + '?sourceMap'
)
})
baseConfig.module.preLoaders.push({
2017-07-25 17:06:49 +08:00
test: /\.(js|jsx)$/,
exclude: /node_modules/,
loader: "eslint-loader"
2017-07-25 15:07:55 +08:00
});
2017-07-25 17:06:49 +08:00
if (this.env == 'prd') {
baseConfig.plugins.push(assetsPluginInstance)
}
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-07-20 16:27:10 +08:00
hot: true
2017-07-06 14:25:52 +08:00
// true/false默认 false开启后可在当前打开的页面提示打包错误
2017-07-20 16:27:10 +08:00
// overlay: true
2017-07-06 14:25:52 +08:00
},
hooks: {},
commands: []
2017-07-05 19:31:50 +08:00
};