Skip to content

Commit

Permalink
新增static功能,优化postcss的autoprefixer功能
Browse files Browse the repository at this point in the history
  • Loading branch information
alanchenchen committed Dec 12, 2018
1 parent 6fb3419 commit 88b6e1d
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 9 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ A react template with webpack for building your react SPA
```
> 强烈建议按照模板目录来进行开发,可以新增,不要删除
* assets是静态资源,componets是组件,router是路由(已配置好),views是页面级组件
* assets是资源,componets是组件,router是路由(已配置好),views是页面级组件,static是静态资源(最终会复制一份到dist的static目录下)
* 基于react-router-dom,模板对Route组件进行了封装,为了更简单实现多层嵌套路由,模仿vue-router的api
* 模板提供了3个路径符号,@ => src目录components => src/components目录views => src/views目录
* 模板提供了3个路径符号,`@ => src目录``components => src/components目录``views => src/views目录``static => static目录`

### 使用
1. git clone https://github.com/alanchenchen/react-template.git 或者使用alan-cli来安装
Expand Down
14 changes: 12 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-template",
"version": "1.2.1",
"version": "1.3.0",
"description": "A react webpack-template for building SPA",
"main": "index.js",
"scripts": {
Expand All @@ -27,6 +27,7 @@
"babel-preset-react": "^6.24.1",
"babel-preset-stage-3": "^6.24.1",
"clean-webpack-plugin": "^0.1.17",
"copy-webpack-plugin": "^4.6.0",
"cross-env": "^5.1.1",
"css-loader": "^0.28.7",
"express": "^4.16.3",
Expand All @@ -45,5 +46,14 @@
"webpack": "^3.8.1",
"webpack-dev-server": "^2.9.4",
"webpack-merge": "^4.1.1"
}
},
"browserslist": [
"> 5%",
"last 2 versions",
"Firefox ESR",
"ie >= 8",
"iOS >= 8",
"Android > 4.4",
"not Opera <= 12.1"
]
}
Empty file added static/.gitkeep
Empty file.
13 changes: 11 additions & 2 deletions webpack.config/webpack.base.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const path = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin')//生成一个html,自动嵌入打包后的js和css
const CopyWebpackPlugin = require('copy-webpack-plugin')
const ROOTPATH = process.cwd() //获取进程的根绝对路径
const env = process.env.NODE_ENV //获取进程的模式是开发环境还是生产环境
const isProduction = env == 'production'
Expand Down Expand Up @@ -68,13 +69,21 @@ module.exports = {
},
// necessary to consistently work with multiple chunks via CommonsChunkPlugin
chunksSortMode: 'dependency'
})
}),
new CopyWebpackPlugin([
{
from: path.resolve(ROOTPATH, 'static'),
to: path.resolve(ROOTPATH, 'dist/static'),
ignore: ['.*']
}
])
],
resolve: {
alias: {
'@': path.resolve(ROOTPATH, 'src'),
'components': path.resolve(ROOTPATH, 'src/components'),
'views': path.resolve(ROOTPATH, 'src/views')
'views': path.resolve(ROOTPATH, 'src/views'),
'static': path.resolve(ROOTPATH, 'static')
},
extensions: ['.js', '.jsx', '.json', '.css', '.less', '.styl']
},
Expand Down
4 changes: 2 additions & 2 deletions webpack.config/webpack.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ const devConfig = (port) =>{
},
{
test: /\.less$/i,//打包less
use: ['style-loader', 'css-loader', 'less-loader']
use: ['style-loader', 'css-loader', 'postcss-loader', 'less-loader']
},
{
test: /\.styl$/i,//打包stylus
use: ['style-loader', 'css-loader', 'stylus-loader']
use: ['style-loader', 'css-loader', 'postcss-loader', 'stylus-loader']
}
]
},
Expand Down
2 changes: 2 additions & 0 deletions webpack.config/webpack.prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ module.exports = merge(common, {
sourceMap
}
},
'postcss-loader',
'less-loader']
})
},
Expand All @@ -61,6 +62,7 @@ module.exports = merge(common, {
sourceMap
}
},
'postcss-loader',
'stylus-loader']
})
}
Expand Down
53 changes: 52 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,11 @@ array-unique@^0.3.2:
resolved "https://registry.yarnpkg.com/array-unique/-/array-unique-0.3.2.tgz#a894b75d4bc4f6cd679ef3244a9fd8f46ae2d428"
integrity sha1-qJS3XUvE9s1nnvMkSp/Y9Gri1Cg=

arrify@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/arrify/-/arrify-1.0.1.tgz#898508da2226f380df904728456849c1501a4b0d"
integrity sha1-iYUI2iIm84DfkEcoRWhJwVAaSw0=

asn1.js@^4.0.0:
version "4.10.1"
resolved "https://registry.yarnpkg.com/asn1.js/-/asn1.js-4.10.1.tgz#b9c2bf5805f1e64aadeed6df3a2bfafb5a73f5a0"
Expand Down Expand Up @@ -1552,6 +1557,20 @@ copy-descriptor@^0.1.0:
resolved "https://registry.yarnpkg.com/copy-descriptor/-/copy-descriptor-0.1.1.tgz#676f6eb3c39997c2ee1ac3a924fd6124748f578d"
integrity sha1-Z29us8OZl8LuGsOpJP1hJHSPV40=

copy-webpack-plugin@^4.6.0:
version "4.6.0"
resolved "https://registry.yarnpkg.com/copy-webpack-plugin/-/copy-webpack-plugin-4.6.0.tgz#e7f40dd8a68477d405dd1b7a854aae324b158bae"
integrity sha512-Y+SQCF+0NoWQryez2zXn5J5knmr9z/9qSQt7fbL78u83rxmigOy8X5+BFn8CFSuX+nKT8gpYwJX68ekqtQt6ZA==
dependencies:
cacache "^10.0.4"
find-cache-dir "^1.0.0"
globby "^7.1.1"
is-glob "^4.0.0"
loader-utils "^1.1.0"
minimatch "^3.0.4"
p-limit "^1.0.0"
serialize-javascript "^1.4.0"

core-js@^2.4.0, core-js@^2.5.0:
version "2.5.7"
resolved "https://registry.yarnpkg.com/core-js/-/core-js-2.5.7.tgz#f972608ff0cead68b841a16a932d0b183791814e"
Expand Down Expand Up @@ -1913,6 +1932,14 @@ diffie-hellman@^5.0.0:
miller-rabin "^4.0.0"
randombytes "^2.0.0"

dir-glob@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/dir-glob/-/dir-glob-2.0.0.tgz#0b205d2b6aef98238ca286598a8204d29d0a0034"
integrity sha512-37qirFDz8cA5fimp9feo43fSuRo2gHwaIn6dXL8Ber1dGwUosDrGZeCCXq57WnIqE4aQ+u3eQZzsk1yOzhdwag==
dependencies:
arrify "^1.0.1"
path-type "^3.0.0"

dns-equal@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/dns-equal/-/dns-equal-1.0.0.tgz#b39e7f1da6eb0a75ba9c17324b34753c47e0654d"
Expand Down Expand Up @@ -2666,6 +2693,18 @@ globby@^6.1.0:
pify "^2.0.0"
pinkie-promise "^2.0.0"

globby@^7.1.1:
version "7.1.1"
resolved "https://registry.yarnpkg.com/globby/-/globby-7.1.1.tgz#fb2ccff9401f8600945dfada97440cca972b8680"
integrity sha1-+yzP+UAfhgCUXfral0QMypcrhoA=
dependencies:
array-union "^1.0.1"
dir-glob "^2.0.0"
glob "^7.1.2"
ignore "^3.3.5"
pify "^3.0.0"
slash "^1.0.0"

graceful-fs@^4.1.11, graceful-fs@^4.1.2:
version "4.1.11"
resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.1.11.tgz#0e8bdfe4d1ddb8854d64e04ea7c00e2a026e5658"
Expand Down Expand Up @@ -2951,6 +2990,11 @@ ignore-walk@^3.0.1:
dependencies:
minimatch "^3.0.4"

ignore@^3.3.5:
version "3.3.10"
resolved "https://registry.yarnpkg.com/ignore/-/ignore-3.3.10.tgz#0a97fb876986e8081c631160f8f9f389157f0043"
integrity sha512-Pgs951kaMm5GXP7MOvxERINe3gsaVjUWFm+UZPSq9xYriQAksyhg0csnS0KXSNRD5NmNdapXEpjxG49+AKh/ug==

import-cwd@^2.0.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/import-cwd/-/import-cwd-2.1.0.tgz#aa6cf36e722761285cb371ec6519f53e2435b0a9"
Expand Down Expand Up @@ -4186,7 +4230,7 @@ p-finally@^1.0.0:
resolved "https://registry.yarnpkg.com/p-finally/-/p-finally-1.0.0.tgz#3fbcfb15b899a44123b34b6dcc18b724336a2cae"
integrity sha1-P7z7FbiZpEEjs0ttzBi3JDNqLK4=

p-limit@^1.1.0:
p-limit@^1.0.0, p-limit@^1.1.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/p-limit/-/p-limit-1.3.0.tgz#b86bd5f0c25690911c7590fcbfc2010d54b3ccb8"
integrity sha512-vvcXsLAJ9Dr5rQOPk7toZQZJApBl2K4J6dANSsEuh6QI41JYcsS/qhTGa9ErIUUgK3WNQoJYvylxvjqmiqEA9Q==
Expand Down Expand Up @@ -4342,6 +4386,13 @@ path-type@^2.0.0:
dependencies:
pify "^2.0.0"

path-type@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/path-type/-/path-type-3.0.0.tgz#cef31dc8e0a1a3bb0d105c0cd97cf3bf47f4e36f"
integrity sha512-T2ZUsdZFHgA3u4e5PfPbjd7HDDpxPnQb5jN0SrDsjNSuVXHJqtwTnWqG0B1jZrgmJ/7lj1EmVIByWt1gxGkWvg==
dependencies:
pify "^3.0.0"

pbkdf2@^3.0.3:
version "3.0.16"
resolved "https://registry.yarnpkg.com/pbkdf2/-/pbkdf2-3.0.16.tgz#7404208ec6b01b62d85bf83853a8064f8d9c2a5c"
Expand Down

0 comments on commit 88b6e1d

Please sign in to comment.