首先npm install webpack-cli
export const a = 1; export const b = 2; export const c = 3;
import * as constants from ‘./test‘;
console.log(constants.a);
<!doctype html> <html> <head> <meta charset="utf-8"> <title>demo</title> </head> <body> <script src="dist/bundle.js"></script> </dody> </html>
{
"name":"Module",
"version": "1.0.0",
"dependencies": {
},
"devDependencies": {
"babel":"^6.23.0",
"babel-cli": "^6.24.1",
"babel-core":"^6.24.1",
"babel-loader": "^7.0.0",
"babel-preset-es2015":"^6.24.1",
"webpack":"^2.6.1"
}
}
var webpack = require("webpack"); var path = require("path"); module.exports = { entry:‘./app.js‘, output:{ path:path.resolve(__dirname,‘dist‘), filename:‘bundle.js‘ }, module:{ loaders:[ {test:/\\.js$/,loader:‘babel-loader‘} ] } }
{ "presets":[ "es2015" ], "plugins":[] }
然后npm install
最后webpack