Authored by huangyi

优化结构

... ... @@ -5,6 +5,7 @@
"stage-0"
],
"plugins": [
"react-loadable/babel",
"transform-runtime",
"syntax-dynamic-import"
]
... ...
const currentApp = 'guoChao';
export default {
production: {
routerPath: {
guoChao: '/html5/2018/09/guochao',
},
domain: 'https://action.yoho.cn',
currentApp
},
development: {
routerPath: {
guoChao: '',
},
domain: '//yoho-activity-platform.test3.ingress.dev.yohocorp.com',
currentApp
}
}[process.env.NODE_ENV || 'development']
\ No newline at end of file
... ...
... ... @@ -8,10 +8,10 @@
"description": "",
"main": "app.js",
"scripts": {
"build": "webpack --mode development --config ./app/guoChao/webpack.config.babel.js ",
"start": "webpack-dev-server --mode development --config ./app/guoChao/webpack.config.babel.js",
"build-prd": "webpack --mode production --config ./app/guoChao/webpack.config.babel.js ",
"start-prd": "webpack-dev-server --mode production --config ./app/guoChao/webpack.config.babel.js"
"build": "webpack --mode development --config ./webpack.config.babel.js ",
"start": "webpack-dev-server --mode development --config ./webpack.config.babel.js",
"build-prd": "webpack --mode production --config ./webpack.config.babel.js ",
"start-prd": "webpack-dev-server --mode production --config ./webpack.config.babel.js"
},
"dependencies": {
"dateformat": "^3.0.3",
... ... @@ -20,13 +20,13 @@
"moment-timezone": "^0.5.15",
"prop-types": "^15.6.1",
"react": "^16.3.2",
"react-cookies": "^0.1.0",
"react-dom": "^16.3.2",
"react-lazy-load": "^3.0.13",
"react-loadable": "^5.5.0",
"react-moment": "^0.7.0",
"react-router-dom": "^4.2.2",
"react-slick": "^0.23.1",
"react-loadable": "^5.5.0",
"react-cookies": "^0.1.0",
"react-lazy-load":"^3.0.13",
"weixin-js-sdk": "^1.3.3"
},
"devDependencies": {
... ... @@ -35,8 +35,8 @@
"babel-core": "^6.26.0",
"babel-loader": "^7.1.4",
"babel-plugin-import": "^1.7.0",
"babel-plugin-transform-runtime": "^6.23.0",
"babel-plugin-syntax-dynamic-import": "^6.18.0",
"babel-plugin-transform-runtime": "^6.23.0",
"babel-preset-env": "^1.6.1",
"babel-preset-es2015": "^6.24.1",
"babel-preset-react": "^6.24.1",
... ... @@ -61,7 +61,7 @@
"style-loader": "^0.20.3",
"url-loader": "^1.0.1",
"webpack": "^4.17.2",
"webpack-cli": "^2.0.14",
"webpack-cli": "^3.1.2",
"webpack-dev-server": "^3.1.3",
"webpack-merge": "^4.1.4"
},
... ...
... ... @@ -2,18 +2,47 @@ import webpack,{DefinePlugin} from 'webpack';
import path from 'path';
import ExtractTextPlugin from "extract-text-webpack-plugin";
import CleanWebpackPlugin from 'clean-webpack-plugin';
import HtmlWebpackPlugin from "html-webpack-plugin";
import config from "./config";
let pathsToClean = [
'build'
];
let cleanOptions = {
root: __dirname,
verbose: true,
dry: false
root: __dirname,
verbose: true,
dry: false
};
let baseArr = [
new DefinePlugin({//全局变量
PRODUCTION: false
}),
new ExtractTextPlugin('css/[name].[chunkhash:8].css'),//css分离
new CleanWebpackPlugin(pathsToClean, cleanOptions),//清除历史版本
];
let htmls = function () {
const title = require('./app/' + config.currentApp + '/title');
let arr = [];
for (let i in title) {
arr.push(new HtmlWebpackPlugin({
filename: i + '.html',
template: './index.ejs',
title: title[i],
inject: true,
minify: {
removeComments: true,
collapseWhitespace: true,
removeAttributeQuotes: true
}
}))
}
arr = arr.concat(baseArr);
return arr
};
module.exports = {
//项目入口js文件
entry: ['./app/index.js'],
//项目输出目录
output: {
chunkFilename: 'routes/[name].[chunkhash:8].chunk.js',
... ... @@ -21,13 +50,7 @@ module.exports = {
filename: '[name].[chunkhash:8].js',
},
//插件
plugins: [
new DefinePlugin({//全局变量
PRODUCTION: false
}),
new ExtractTextPlugin('css/[name].[chunkhash:8].css'),//css分离
new CleanWebpackPlugin(pathsToClean, cleanOptions),//清除历史版本
],
plugins: htmls(),
//加载器
module: {
rules: [
... ... @@ -70,6 +93,7 @@ module.exports = {
]
},
devServer: {
publicPath: config.routerPath[config.currentApp],
port: 8080,
disableHostCheck: true,
},
... ...