Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add new content and sample codes: webpack for production
- Loading branch information
1 parent
940ad07
commit bf70985
Showing
8 changed files
with
273 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<html> | ||
<head> | ||
<title> This is the example for Dynamic Imports </title> | ||
</head> | ||
<body> | ||
<script src="index.bundle.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import React from 'react' | ||
import { render } from 'react-dom' | ||
import './style.css' | ||
|
||
var container = document.body.appendChild( | ||
document.createElement('div') | ||
) | ||
|
||
var element = React.createElement( | ||
'h1', | ||
null, | ||
'Hello, world!' | ||
); | ||
|
||
render(element, container) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"name": "part9", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"scripts": { | ||
"build": "webpack --config webpack.prod.js" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC", | ||
"devDependencies": { | ||
"css-loader": "^0.28.7", | ||
"extract-text-webpack-plugin": "^3.0.2", | ||
"html-webpack-plugin": "^2.30.1", | ||
"style-loader": "^0.19.1", | ||
"webpack": "^3.5.2" | ||
}, | ||
"dependencies": { | ||
"react": "^16.2.0", | ||
"react-dom": "^16.2.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
body { | ||
background: yellow; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
const HtmlWebpackPlugin = require('html-webpack-plugin'); //installed via npm | ||
const ExtractTextPlugin = require("extract-text-webpack-plugin"); | ||
const webpack = require('webpack'); //to access built-in plugins | ||
const path = require('path'); | ||
|
||
module.exports = { | ||
// 入口文件名称 | ||
entry: { | ||
index: './index.js', | ||
vendor: ['react', 'react-dom'], | ||
}, | ||
// 输出文件名称 | ||
output: { | ||
path: path.resolve(__dirname, 'dist'), | ||
filename: '[name].bundle.js', | ||
}, | ||
devtool: 'source-map', | ||
module: { | ||
rules: [ | ||
{ | ||
test: /\.css$/, | ||
use: ExtractTextPlugin.extract({ | ||
fallback: "style-loader", | ||
use: ['css-loader'] | ||
}) | ||
} | ||
] | ||
}, | ||
plugins: [ | ||
new webpack.DefinePlugin({ | ||
'process.env.NODE_ENV': JSON.stringify('production') | ||
}), | ||
new webpack.optimize.UglifyJsPlugin({ | ||
sourceMap: true | ||
}), | ||
new ExtractTextPlugin("styles.css"), | ||
new webpack.optimize.CommonsChunkPlugin({ | ||
name: "vendor" | ||
}), | ||
new HtmlWebpackPlugin({ | ||
title: 'Test App', | ||
}) | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.