npm run build
npm install webpack ‐g
npm install webpack‐cli ‐g
webpack ‐v
exports.info=function(str){
document.write(str);
}
exports.add=function(a,b){
return a+b;
}
var bar= require('./bar');
var logic= require('./logic');
bar.info( 'Hello world!'+ logic.add(100,200));
var path = require("path");
module.exports = {
entry: './src/main.js',
output: {
path: path.resolve(__dirname, './dist'),
filename: 'bundle.js'
}
};
webpack
<!doctype html>
<html>
<head>
</head>
<body>
<script src="dist/bundle.js"></script>
</body>
</html>
cnpm install style‐loader css‐loader ‐‐save‐dev
var path = require("path");
module.exports = {
entry: './src/main.js',
output: {
path: path.resolve(__dirname, './dist'),
filename: 'bundle.js'
},
module: {
rules: [
{
test: /\.css$/,
use: ['style‐loader', 'css‐loader']
}
]
}
};
body{
background:red;
}
require('./css1.css');
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) | 黑马程序员IT技术论坛 X3.2 |