Commit a4387fd9 by 万亚飞

修改配置

parent d2199f3e
const path = require('path');
const webpack = require('webpack');
function resolveRoot(dir) {
return path.join(__dirname, '..', dir);
}
module.exports = {
entry: {
vendor: ['babel-polyfill', 'react'],
app: resolveRoot('src/index.js')
},
output: {
filename: 'js/[name].[contenthash:8].js',
path: resolveRoot('dist')
},
plugins: [new webpack.NamedModulesPlugin()],
resolve: {
extensions: ['.js', '.json', '.jsx', '.vue', '.scss', '.less'],
alias: {
'@utils': resolveRoot('src/utils/index.js'),
'@static': resolveRoot('src/static'),
'@': resolveRoot('src')
}
},
optimization: {
runtimeChunk: true,
splitChunks: {
chunks: 'all'
}
}
};
...@@ -3,19 +3,20 @@ const path = require('path'); ...@@ -3,19 +3,20 @@ const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin'); const HtmlWebpackPlugin = require('html-webpack-plugin');
const webpack = require('webpack'); const webpack = require('webpack');
const os = require('os'); const os = require('os');
const env = require(`./dev.env`); const merge = require('webpack-merge');
const base = require('./webpack.base.js');
const env = require(`../config/dev.env`);
function resolveRoot(dir) { function resolveRoot(dir) {
return path.join(__dirname, '..', dir); return path.join(__dirname, '..', dir);
} }
module.exports = { module.exports = merge(base, {
entry: { // entry: {
app: ['babel-polyfill', './src/index.js'], // vendor: ['react', 'better-scroll', 'react-redux', 'react-lazyload']
vendor: ['react', 'better-scroll', 'react-redux', 'react-lazyload'] // },
},
output: { output: {
publicPath: '/', publicPath: '/'
filename: 'js/[name].[hash:8].js', // filename: 'js/[name].[hash:8].js',
path: resolve(__dirname, '../build')
}, },
module: { module: {
rules: [ rules: [
...@@ -105,10 +106,9 @@ module.exports = { ...@@ -105,10 +106,9 @@ module.exports = {
'process.env': env 'process.env': env
}), }),
new HtmlWebpackPlugin({ new HtmlWebpackPlugin({
template: './public/index.html' template: resolveRoot('index.html')
}), }),
new webpack.HotModuleReplacementPlugin(), new webpack.HotModuleReplacementPlugin()
new webpack.NamedModulesPlugin()
], ],
mode: 'development', mode: 'development',
devServer: { devServer: {
...@@ -118,19 +118,5 @@ module.exports = { ...@@ -118,19 +118,5 @@ module.exports = {
open: true, open: true,
port: 5000, port: 5000,
hot: true hot: true
},
resolve: {
extensions: ['.js', '.json', '.jsx', '.vue', '.scss', '.less'],
alias: {
'@utils': resolveRoot('src/utils/index.js'),
'@static': resolveRoot('src/static'),
'@': resolveRoot('src')
}
},
optimization: {
runtimeChunk: true,
splitChunks: {
chunks: 'all'
}
} }
}; });
...@@ -8,22 +8,20 @@ const CleanWebpackPlugin = require('clean-webpack-plugin'); ...@@ -8,22 +8,20 @@ const CleanWebpackPlugin = require('clean-webpack-plugin');
const OptimizeCssAssetsWebpackPlugin = require('optimize-css-assets-webpack-plugin'); const OptimizeCssAssetsWebpackPlugin = require('optimize-css-assets-webpack-plugin');
const PrerenderSPAPlugin = require('prerender-spa-plugin'); const PrerenderSPAPlugin = require('prerender-spa-plugin');
const PreloadWebpackPlugin = require('preload-webpack-plugin'); const PreloadWebpackPlugin = require('preload-webpack-plugin');
const env = require(`./${process.env.ENV_MARK}.env`);
console.log('env', process.env.ENV_MARK, env); const merge = require('webpack-merge');
const base = require('./webpack.base.js');
const env = require(`../config/${process.env.ENV_MARK}.env`);
const os = require('os'); const os = require('os');
function resolveRoot(dir) { function resolveRoot(dir) {
return path.join(__dirname, '..', dir); return path.join(__dirname, '..', dir);
} }
module.exports = { module.exports = merge(base, {
entry: {
app: ['babel-polyfill', './src/index.js'],
vendor: ['react']
},
output: { output: {
publicPath: '/new/', publicPath: '/new/'
filename: 'js/[name].[contenthash:8].js', // filename: 'js/[name].[contenthash:8].js'
path: resolve(__dirname, '../dist')
}, },
module: { module: {
rules: [ rules: [
...@@ -151,7 +149,8 @@ module.exports = { ...@@ -151,7 +149,8 @@ module.exports = {
'process.env': env 'process.env': env
}), }),
new HtmlWebpackPlugin({ new HtmlWebpackPlugin({
template: './public/index.html', template: resolveRoot('index.html'),
favicon: 'favicon.ico',
minify: { minify: {
removeComments: true, removeComments: true,
collapseWhitespace: true, collapseWhitespace: true,
...@@ -165,6 +164,21 @@ module.exports = { ...@@ -165,6 +164,21 @@ module.exports = {
minifyURLs: true minifyURLs: true
} }
}), }),
new MiniCssExtractPlugin({
filename: 'css/[name].[contenthash:8].css'
}),
new CleanWebpackPlugin(),
new OptimizeCssAssetsWebpackPlugin({
cssProcessPluginOptions: {
preset: ['default', { discardComments: { removeAll: true } }]
}
}),
new webpack.HashedModuleIdsPlugin()
// new PrerenderSPAPlugin({
// routes: ['/', '/home', '/shop'],
// staticDir: resolve(__dirname, '../dist')
// })
// new PreloadWebpackPlugin({ // new PreloadWebpackPlugin({
// rel: 'preload', // rel: 'preload',
// as(entry) { // as(entry) {
...@@ -176,41 +190,12 @@ module.exports = { ...@@ -176,41 +190,12 @@ module.exports = {
// include: 'allChunks' // include: 'allChunks'
// //include: ['app'] // //include: ['app']
// }), // }),
new webpack.NamedModulesPlugin(),
// new WorkboxPlugin.GenerateSW({ // new WorkboxPlugin.GenerateSW({
// clientsClaim: true, // clientsClaim: true,
// skipWaiting: true, // skipWaiting: true,
// importWorkboxFrom: 'local', // importWorkboxFrom: 'local',
// include: [/\.js$/, /\.css$/, /\.html$/, /\.jpg/, /\.jpeg/, /\.svg/, /\.webp/, /\.png/] // include: [/\.js$/, /\.css$/, /\.html$/, /\.jpg/, /\.jpeg/, /\.svg/, /\.webp/, /\.png/]
// }), // }),
new MiniCssExtractPlugin({
filename: 'css/[name].[contenthash:8].css'
}),
new CleanWebpackPlugin(),
new OptimizeCssAssetsWebpackPlugin({
cssProcessPluginOptions: {
preset: ['default', { discardComments: { removeAll: true } }]
}
}),
new webpack.HashedModuleIdsPlugin()
// new PrerenderSPAPlugin({
// routes: ['/', '/home', '/shop'],
// staticDir: resolve(__dirname, '../dist')
// })
], ],
mode: 'production', mode: 'production'
resolve: { });
extensions: ['.js', '.json', '.jsx', '.vue', '.scss', '.less'],
alias: {
'@utils': resolveRoot('src/utils/index.js'),
'@static': resolveRoot('src/static'),
'@': resolveRoot('src')
}
},
optimization: {
runtimeChunk: true,
splitChunks: {
chunks: 'all'
}
}
};
...@@ -70,20 +70,26 @@ ...@@ -70,20 +70,26 @@
"workbox-webpack-plugin": "^4.3.1" "workbox-webpack-plugin": "^4.3.1"
}, },
"scripts": { "scripts": {
"start": "webpack-dev-server --config ./config/webpack.dev.js", "start": "better-npm-run build:dev",
"dev": "webpack-dev-server --config ./config/webpack.dev.js", "dev": "better-npm-run build:dev",
"build:test": "better-npm-run build:test", "build:test": "better-npm-run build:test",
"build:prod": "better-npm-run build:test" "build:prod": "better-npm-run build:prod"
}, },
"betterScripts": { "betterScripts": {
"build:dev": {
"command": "webpack --config ./build/webpack.dev.js",
"env": {
"ENV_MARK": "development"
}
},
"build:test": { "build:test": {
"command": "webpack --config ./config/webpack.prod.js", "command": "webpack --config ./build/webpack.prod.js",
"env": { "env": {
"ENV_MARK": "testing" "ENV_MARK": "testing"
} }
}, },
"build:prod": { "build:prod": {
"command": "webpack --config ./config/webpack.prod.js", "command": "webpack --config ./build/webpack.prod.js",
"env": { "env": {
"ENV_MARK": "production" "ENV_MARK": "production"
} }
...@@ -92,7 +98,9 @@ ...@@ -92,7 +98,9 @@
"devDependencies": { "devDependencies": {
"@babel/plugin-syntax-dynamic-import": "^7.2.0", "@babel/plugin-syntax-dynamic-import": "^7.2.0",
"better-npm-run": "^0.1.1", "better-npm-run": "^0.1.1",
"preload-webpack-plugin": "^3.0.0-beta.3" "copy-webpack-plugin": "^5.0.3",
"preload-webpack-plugin": "^3.0.0-beta.3",
"webpack-merge": "^4.2.1"
}, },
"theme": { "theme": {
"brand-primary": "red", "brand-primary": "red",
......
import React from 'react'; import React from 'react';
import { Tabs, Badge, Carousel, NoticeBar } from 'antd-mobile'; import { Tabs, Badge, Carousel, NoticeBar } from 'antd-mobile';
import BScroll from 'better-scroll'; // import BScroll from 'better-scroll';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import LazyLoad, { forceCheck } from 'react-lazyload'; import LazyLoad, { forceCheck } from 'react-lazyload';
import './index.less'; import './index.less';
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment