Webpack is a module bundler for modern JavaScript applications
https://webpack.js.org
module.exports = {
entry: './path/to/my/entry/file.js'
};
const path = require('path');
module.exports = {
entry: './path/to/my/entry/file.js',
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'my-first-webpack.bundle.js'
}
};
const path = require('path');
module.exports = {
entry: './path/to/my/entry/file.js',
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'my-first-webpack.bundle.js'
},
module: {
rules: [
{test: /\.css$/, use: ['style-loader', 'css-loader']}
]
}
};
const webpack = require('webpack'); //to access built-in plugins
const path = require('path');
module.exports = {
entry: './path/to/my/entry/file.js',
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'my-first-webpack.bundle.js'
},
module: {
rules: [
{ test: /\.css$/, use: ['style-loader', 'css-loader'] }
]
},
plugins: [
new webpack.optimize.UglifyJsPlugin()
]
};
var commonjs = require('./_commonjs');
//_common.js
module.exports = "Hello Common JS";
var amd = require('./_amd');
//_amd.js
define([], function() {
return "Hello AMD";
});
import es6 from './_es6';
//_es6.js
export default "Hello ES6-modules";
var ensurePromise = new Promise(function(resolve) {
require.ensure(['./_ensure'], function(require) {
var data = require('./_ensure');
resolve(data);
});
});
//_ensure.js
module.exports = 'Ensure syntax';
const importStatic = import('./_import');
//_import.js
export default "Import syntax";
var context = require.context('./', false, /(import|ensure)\.js$/);
context.keys().forEach(function(key){
context(key);
});
const moduleName = '_import';
const dynamicImport = import('./' + moduleName);