Skip to content

Commit a631373

Browse files
committed
feat(common): init project with babel
0 parents  commit a631373

File tree

7 files changed

+5801
-0
lines changed

7 files changed

+5801
-0
lines changed

.babelrc

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"presets": [
3+
"@babel/preset-env"
4+
]
5+
}

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
dist

package-lock.json

+5,712
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"name": "webpack-loader",
3+
"version": "1.0.0",
4+
"description": "webpack-loader demo",
5+
"main": "index.js",
6+
"scripts": {
7+
"start": "npm run dev",
8+
"dev": "webpack",
9+
"build": "webpack --mode production"
10+
},
11+
"author": "scarcoco",
12+
"devDependencies": {
13+
"@babel/core": "^7.6.4",
14+
"@babel/preset-env": "^7.6.3",
15+
"babel-loader": "^8.0.6",
16+
"html-webpack-plugin": "^3.2.0",
17+
"webpack": "^4.41.1",
18+
"webpack-cli": "^3.3.9"
19+
}
20+
}

public/template.html

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<meta http-equiv="X-UA-Compatible" content="ie=edge">
7+
<title>Hello</title>
8+
</head>
9+
<body>
10+
11+
</body>
12+
</html>

src/app.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
export function convert (...args) {
2+
if(args.length <= 0) {
3+
return
4+
}
5+
const words = args.map(arg => arg.toUpperCase())
6+
7+
console.log(args, words)
8+
9+
return words
10+
}
11+
12+
13+
convert('aaaaa', 'bbbbbb', 'cccccc')

webpack.config.js

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
const path = require('path');
2+
const HtmlWebpackPlugin = require('html-webpack-plugin')
3+
4+
const distPath = path.resolve(__dirname, 'dist')
5+
6+
const mode = process.env.NODE_ENV || 'development'
7+
8+
module.exports = {
9+
// production | development | node
10+
// 不同 mode, 默认开启的插件不一样 https://webpack.docschina.org/concepts/mode/#%E7%94%A8%E6%B3%95
11+
mode: mode,
12+
13+
entry: {
14+
app: './src/app.js'
15+
},
16+
output: {
17+
path: distPath,
18+
filename: '[name].bundle.js',
19+
publicPath: '/'
20+
},
21+
module: {
22+
rules: [
23+
{
24+
test: /\.m?js$/,
25+
exclude: /(node_modules|bower_components)/,
26+
use: {
27+
loader: 'babel-loader'
28+
}
29+
}
30+
]
31+
},
32+
plugins: [
33+
new HtmlWebpackPlugin({
34+
template: './public/template.html'
35+
})
36+
]
37+
};

0 commit comments

Comments
 (0)