javascript - webpack loaders and include -
i'm new webpack , i'm trying understand loaders properties such test, loader, include etc.
here sample snippet of webpack.config.js found in google.
module: { loaders: [ { test: /\.js$/, loader: 'babel-loader', include: [ path.resolve(__dirname, 'index.js'), path.resolve(__dirname, 'config.js'), path.resolve(__dirname, 'lib'), path.resolve(__dirname, 'app'), path.resolve(__dirname, 'src') ], exclude: [ path.resolve(__dirname, 'test', 'test.build.js') ], cachedirectory: true, query: { presets: ['es2015'] } }, ] } am right test: /.js$/ used files extension .js?
the loader: 'babel-loader', loader install using npm
the include: have many questions on this. right put inside array transpiled? means, index.js, config.js, , *.js files in lib, app , src transpiled.
more questions on include: when files transpiled, *.js files concatenated 1 big file?
i think exclude self explanatory. not transpiled.
what query: { presets: ['es2015'] } do?
in webpack config there multiple things configuration, important ones are
- entry - can array or object defining entry point asset want bundle, can js test here says /.js$. application if has multiple entry points use array.
- include - defines set of path or files imported files transformed loader.
- exclude self explanatory (do not transform file these places).
output - final bundle want create. if specify example
output: { filename: "[name].bundle.js", vendor: "react" }
then application js files bundled main.bundle.js , react in vendor.js files. error if not use both in html page.
hope helped
Comments
Post a Comment