1 Star 0 Fork 1

快易科技 / react主项目-多个子项目-gy

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
webpack-dev-config.js 5.20 KB
一键复制 编辑 原始数据 按行查看 历史
jswebh5 提交于 2018-02-25 12:37 . 主项目多个子项目
/**
* 开发模式下的webpack配置
* 在整个项目开发过程中,几乎99%的时间都是在这个模式下进行的
* 注意。两种模式的配置有较大差异!!
*/
const path = require('path');
import webpack from 'webpack';
import HtmlWebpackPlugin from 'html-webpack-plugin'
import precss from 'precss'
import autoprefixer from 'autoprefixer'
import rucksackCss from 'rucksack-css'
import px2rem from 'postcss-pxtorem'
import webConfig from './webs-config' //项目配置
const px2remOpts = {
rootValue: 100,
propWhiteList: [],
};
export default {
debug: true,
devtool: 'cheap-module-eval-source-map', // more info:https://webpack.github.io/docs/build-performance.html#sourcemaps and https://webpack.github.io/docs/configuration.html#devtool
noInfo: true, // set to false to see a list of every file being bundled.
entry: [
'./src/webpack-public-path', // 服务器静态资源路径配置,保证首先载入
'react-hot-loader/patch',
'webpack-hot-middleware/client?reload=true',
path.resolve(__dirname, 'src/webs/' + webConfig.name + webConfig.startPath + '/js/index.js')
],
target: 'web', // necessary per https://webpack.github.io/docs/testing.html#compile-and-test
output: {
path: `${__dirname}/src`, // Note: Physical files are only output by the production build task `npm run build`.
publicPath: '/',
filename: 'bundle.js'
},
plugins: [
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('development'), // Tells React to build in either dev or prod modes. https://facebook.github.io/react/downloads.html (See bottom)
__DEV__: true
}),
new webpack.HotModuleReplacementPlugin(),
new webpack.NoErrorsPlugin(),
new HtmlWebpackPlugin({ // Create HTML file that includes references to bundled CSS and JS.
template: 'src/webs/' + webConfig.name + webConfig.startPath + '/index.html',
title: webConfig.title + '开发模式',
favicon: './src/favicon.ico',
minify: {
removeComments: true,
collapseWhitespace: true
},
hash: true,
// 这样每次客户端页面就会根据这个hash来判断页面是否有必要刷新
// 在项目后续过程中,经常需要做些改动更新什么的,一但有改动,客户端页面就会自动更新!
inject: 'body'
})
],
resolve: {
modulesDirectories: ['node_modules', path.join(__dirname, '../node_modules')],
extensions: ['', '.web.js', '.js', '.json'],
// 路径别名, 懒癌福音
alias: {
app: path.resolve(__dirname, 'src/js'),
// 以前你可能这样引用 import { Nav } from '../../components'
// 现在你可以这样引用 import { Nav } from 'app/components'
style: path.resolve(__dirname, 'src/styles')
// 以前你可能这样引用 import "../../../styles/mixins.scss"
// 现在你可以这样引用 import "style/mixins.scss"
// 注意:别名只能在.js文件中使用。
}
},
module: {
rules: [
{
test: /\.css$/,
use: [
'style-loader',
'css-loader',
],
},
{
test: /\.less$/,
use: [
'style-loader',
'css-loader',
{
loader: 'less-loader', options: {
modifyVars: { "@hd": "2px" }
}
},
],
include: path.resolve(__dirname, 'node_modules'),
}
],
loaders: [
{
test: /\.js$/,
loaders: ['babel'],
exclude: /node_modules/
},
{
test: /\.scss$/,
include: path.resolve(__dirname, 'src/js'),
loaders: [
'style',
'css?modules&sourceMap&importLoaders=1&localIdentName=[local]___[hash:base64:5]',
'postcss?parser=postcss-scss'
]
},
// 组件样式,需要私有化,单独配置
{
test: /\.scss$/,
include: path.resolve(__dirname, 'src/styles'),
loader: 'style!css!postcss?parser=postcss-scss'
},
// 公有样式,不需要私有化,单独配置
{
test: /\.scss$/,
include: path.resolve(__dirname, 'src/webs/' + webConfig.name + webConfig.startPath + '/js'),
loaders: [
'style',
'css?modules&importLoaders=1&localIdentName=[local]___[hash:base64:5]',
'postcss?parser=postcss-scss'
]
},
// 项目组件样式,需要私有化,单独配置
{
test: /\.scss$/,
include: path.resolve(__dirname, 'src/webs/' + webConfig.name + webConfig.startPath + '/styles'),
loader: 'style!css!postcss?parser=postcss-scss'
},
// 项目公有样式,不需要私有化,单独配置
{
test: /\.css$/,
include: path.resolve(__dirname, 'node_modules'),
loader: 'style!css!postcss'
},
{
test: /\.less$/,
include: path.resolve(__dirname, 'node_modules'),
loader: 'style!css!less'
},
{
test: /\.(otf|eot|svg|ttf|woff|woff2).*$/,
loader: 'url?limit=10000'
},
{
test: /\.(gif|jpe?g|png|ico)$/,
loader: 'url?limit=10000'
}
]
},
postcss: () => [precss, autoprefixer, rucksackCss, px2rem(px2remOpts)]
};
1
https://gitee.com/gdkstock/react_main_project__multiple_sub_projects_gy.git
git@gitee.com:gdkstock/react_main_project__multiple_sub_projects_gy.git
gdkstock
react_main_project__multiple_sub_projects_gy
react主项目-多个子项目-gy
master

搜索帮助

53164aa7 5694891 3bd8fe86 5694891