Skip to content

Commit

Permalink
webpack模块化打包
Browse files Browse the repository at this point in the history
  • Loading branch information
HackerWand committed Jan 6, 2020
1 parent 8c86252 commit 4bbd2f7
Show file tree
Hide file tree
Showing 10 changed files with 6,530 additions and 2 deletions.
7 changes: 7 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"presets": ["@babel/preset-env"],
"plugins": [
"@babel/plugin-proposal-class-properties",
"@babel/plugin-transform-runtime"
]
}
20 changes: 20 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# ---> macOS
.DS_Store
.AppleDouble
.LSOverride

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk
node_modules
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,25 @@
# ADate
JavaScript的Date对象工具

## 安装和使用
ES6使用方法
```
npm install adate
```
```
import ADate from 'adate'
let date = new ADate()
```

浏览器使用方法
```
<script src="./dist/adate.module.js"></script>
<script>
let date = new ADate()
</script>
```

## 日期格式化 (format)
```
let date = new ADate()
Expand Down
32 changes: 32 additions & 0 deletions build/webpack.common.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const path = require('path');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
// const HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = {
entry: './src/index.js',
plugins: [
new CleanWebpackPlugin(),
// new HtmlWebpackPlugin({
// title: 'Production'
// })
],
output: {
filename: 'adate.module.js',
path: path.resolve('./dist'),
chunkFilename: 'adate.module.js',
library: 'AMap',
// libraryExport: 'default',
libraryTarget: 'umd',
// umdNamedDefine: true,
globalObject: 'this' // 当为一个libray库的时候必须设置为 this 才可以在各种模式下使用
},
module: {
rules: [
{
test: /\.js$/,
loader: 'babel-loader',
exclude: '/node_modules/'
},
]
}
};
8 changes: 8 additions & 0 deletions build/webpack.dev.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const merge = require('webpack-merge');
const common = require('./webpack.common.js');
module.exports = merge(common, {
devtool: 'inline-source-map',
devServer: {
contentBase: './dist'
}
});
16 changes: 16 additions & 0 deletions build/webpack.prod.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const merge = require('webpack-merge');
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
const common = require('./webpack.common.js');
const webpack = require('webpack');

module.exports = merge(common, {
plugins: [
new UglifyJSPlugin({
sourceMap: true
}),
new webpack.DefinePlugin({
// process.env.NODE_ENV
'process.env.NODE_ENV': JSON.stringify('production')
})
]
});
1 change: 1 addition & 0 deletions dist/adate.module.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 4bbd2f7

Please sign in to comment.