javascript - Confusing webpack/ES6 project setup -
i trying setup first es6 , webpack "application" , want use classes , modules. everytime want transpile application via webpack
command following error:
$ webpack hash: c91db5651ec9123b8959 version: webpack 3.5.6 time: 2319ms asset size chunks chunk names app.bundle.js 354 kb 0 [emitted] [big] main index.html 978 bytes [emitted] [0] ./src/app.js 14 kb {0} [built] + 1 hidden module error in ./src/app.js module not found: error: can't resolve 'radar' in 'c:\dev\git\my-first-app\src' @ ./src/app.js 7:13-29 child html-webpack-plugin "index.html": 1 asset [0] ./node_modules/html-webpack-plugin/lib/loader.js!./src/index.html 1.37 kb {0} [built] [2] (webpack)/buildin/global.js 509 bytes {0} [built] [3] (webpack)/buildin/module.js 517 bytes {0} [built] + 1 hidden module
i have got following files
package.json
{ "name": "my-first-app", "version": "1.0.0", "description": "", "main": "webpack.config.js", "scripts": { "build": "./node_modules/.bin/babel src -d dest", "start": "webpack-dev-server" } "devdependencies": { "babel-cli": "^6.26.0", "babel-core": "^6.26.0", "babel-loader": "^7.1.2", "babel-preset-env": "^1.6.0", "babel-preset-es2015": "^6.24.1", "webpack": "^3.5.6" }, "dependencies": { "babel-polyfill": "^6.26.0", "d3": "3.5.17", "html-webpack-plugin": "^2.28.0", "webpack-dev-server": "^2.4.5" } }
webpack.config.js
const path = require('path'); const webpack = require('webpack'); const htmlwebpackplugin = require('html-webpack-plugin'); module.exports = { entry: './src/app.js', output: { path: path.resolve(__dirname, 'dest'), filename: 'app.bundle.js' }, module: { loaders: [ { loader: 'babel-loader', include: [ path.resolve(__dirname, "src") ], test: /\.js$/ } ] }, plugins: [ new htmlwebpackplugin({ template: 'src/index.html', filename: 'index.html', inject: 'body' }) ] };
src/app.js
'use strict'; import * d3 'd3'; import radar 'radar'; var r = new radar(); r.render();
radar.js
'use strict'; import * d3 'd3'; export default class radar { render() { ... } }
the index.html basic html file contains empty document head , body.
i think error somewhere in webpack.config.js or maybe mixed different techniques use es6. commands npm build
not (it seems nothing happens). can me please? bit confused , don't know look/search for...
radar
imported app.js
, not in package.json
dependencies list. can run npm install radar --save
command line install package , save reference in package.json
if radar local file, rather package, need use file path import it. like:
import radar './path/to/file/radar';
here how import statements resolved in webpack - https://webpack.js.org/concepts/module-resolution/
Comments
Post a Comment