javascript - Issues with require in webpack -
i working on older project needs updating. webpack config file looks such:
process.env.uv_threadpool_size = 100; var webpack = require('webpack'), path = require('path'), assetsplugin = require('assets-webpack-plugin'), ngannotateplugin = require('ng-annotate-webpack-plugin'), extracttextplugin = require('extract-text-webpack-plugin'), cleanwebpackplugin = require('clean-webpack-plugin'), bundleanalyzerplugin = require('webpack-bundle-analyzer').bundleanalyzerplugin, env = process.env.node_env, prod = env === 'production' || env === 'analyse', test = env === 'test', analyse = env === 'analyse'; plugins = [ new cleanwebpackplugin( [path.join(__dirname, '..', 'www', 'dist', 'bundles')], { root: process.cwd(), verbose: true, dry: false } ), new webpack.defineplugin({ 'process.env': { 'node_env': json.stringify(env) } }), new webpack.provideplugin({ $: "jquery", jquery: "jquery", "window.jquery": "jquery" }), new assetsplugin({ path: path.join(__dirname, '..'), filename: 'webpack-assets.json' }), new extracttextplugin("[name].[hash].css", { allchunks: true }), new webpack.optimize.commonschunkplugin({ name: 'common', filename: 'common.[hash].js', minchunks: 4 }), ]; if (analyse) { plugins.push(new bundleanalyzerplugin()); } if(prod) { //i leave in now, future work explore impact of removing it. plugins.push(new webpack.optimize.uglifyjsplugin(), new ngannotateplugin({ add: true })) } var config = { context: __dirname, entry: { registerinterest : './entryscripts/aa/a.js', qualification : './entryscripts/bb/b.js', curation : './entryscripts/cc/c.js', iepolyfills : ['classlist-polyfill', 'ie9-oninput-polyfill'] }, output: { path: path.join(__dirname, '..', 'www', 'dist', 'bundles'), publicpath: '/dist/bundles/', filename: '[name].[hash].js' }, devtool: 'source-map', devserver: { stats: 'minimal' }, module: { loaders: [ { test: /\.jsx?$/, include: [ path.resolve(__dirname), path.resolve(__dirname, '../node_modules/punycode') ], loader: 'babel-loader', query: { presets: ['es2015', 'react'] } }, { test: /\.(scss|css)$/, loader: extracttextplugin.extract("style-loader", `css-loader?minimize=${prod}!sass-loader`) }, { test: /\.(png|jpg)$/, loader: "url-loader?limit=100000" }, { test: /\.(eot|ttf|svg|woff|woff2)/, loader: 'file-loader' }, { test: /\.(json)/, loader: 'json-loader' }, ], }, plugins: plugins }; module.exports = config; i added in angular code, , trying use require syntax used elsewhere in code follows:
function(angular) { "use strict"; angular.module("mattsmodule", [ "nganimate", "claims", "apiclaims", "impliedequity", "filesize", "angular-sortable-view", "numbersonly", "scrollto", require('../../../../apps/directives/custom-angular-datepicker') ]); })(angular); i added new entryscript js files wrote literally import files used:
import '../../apps/components/box-accordion-alt/box-accordion-alt'; import '../../apps/invite'; import '../../apps/opportunity/views/base'; if npm build this, builds fine recieve error:
uncaught referenceerror: require not defined if remove line
require('../../../../apps/directives/custom-angular-datepicker') it loads fine , works expect. can validate server finds file, if break path , make it
require('.././../../apps/directives/custom-angular-datepicker') the webpack dev server says cannot find file.
i unsure go here. how can debug this? step missing?
Comments
Post a Comment