(Node.js and yarn required)
yarn create cx-app demo-app
cd demo-app
yarn start
const path = require('path');
const config = {
entry: './path/to/my/entry/file.js',
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'my-first-webpack.bundle.js'
},
module: {
rules: [
{ test: /\.js/, use: 'babel-loader' }
]
},
plugins: []
};
module.exports = config;
webpack loaders transform all types of files into your application's dependency graph:
{
test: /\.js$/,
//register here any ES6 based library
include: (app|cx|cx-react|cx-google-maps)[\\\/]/,
loader: 'babel-loader',
query: {
presets: [
["cx-env", {
targets: {
chrome: 50,
ie: 11,
ff: 30,
edge: 12,
safari: 9
},
modules: false,
loose: true,
useBuiltIns: true,
cx: {
imports: {
useSrc: true
}
}
}]
]
}
}
devServer: {
port: 8088,
historyApiFallback: true,
proxy: {
'/api': {
target: 'https://other-server.example.com',
secure: false
}
},
hot: true,
inline: true
},
plugins: [
new webpack.HotModuleReplacementPlugin()
]
//CxJS store
const store = new Store();
//webpack (HMR)
if (module.hot) {
//register module for HMR
module.hot.accept();
// remember data on dispose
module.hot.dispose(function (data) {
data.state = store.getData();
if (stop)
stop();
});
//apply data on hot replace
if (module.hot.data)
store.load(module.hot.data.state);
}
Splits your codebase into “chunks” which are loaded on demand. You define split points in your code and Webpack takes care of the dependencies, output files and runtime stuff.
import(/* webpackChunkName: 'map' */ "./map")
.then(module => {
//do stuff with map loaded
});
plugins: [
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('production')
}),
new webpack.optimize.ModuleConcatenationPlugin(), // scope hoisting
new webpack.optimize.UglifyJsPlugin()
]
output: {
filename: "[name].[chunkhash].js",
chunkFilename: '[name].[chunkhash].js',
hashDigestLength: 5,
}