module.exports = function(options) { DEV_SERVER = options && options['live'] || false; const METADATA = { host: HOST, port: PORT, ENV: ENV, DEV_SERVER: DEV_SERVER }; const entry = { 'index': './src/main.electron.ts' }; const otherFilesToCompile = []; const tsConfigBase = 'tsconfig.webpack.json'; const customTsConfigFileName = 'tsconfig.main.temp.json'; const atlConfig = { configFileName: customTsConfigFileName }; return { name: "main", devtool: PROD ? 'source-map' : 'cheap-module-source-map', entry: entry, output: { path: DEV_SERVER ? helpers.root('dev') : helpers.root('dist'), filename: '[name].js', sourceMapFilename: '[file].map' }, resolve: { extensions: ['.ts', '.js', 'json'] }, module: { rules: [ { test: /\.ts$/, loader: 'awesome-typescript-loader?' + JSON.stringify(atlConfig) }, { test: /\.json$/, loader: 'json-loader' } ] }, node: { __dirname: false, __filename: false }, externals: [nodeExternals()], plugins: [ PROD ? new NoEmitOnErrorsPlugin() : null, new webpack.DefinePlugin(METADATA), new CheckerPlugin(), new webpack.IgnorePlugin(new RegExp("^(spawn-sync|bufferutil|utf-8-validate)$")), new SpecifyTsFilesPlugin({ root: helpers.root('.'), entry: entry, otherFilesToCompile: otherFilesToCompile, tsConfigBase: tsConfigBase, customTsConfigFileName: customTsConfigFileName }), PROD ? new UglifyJsPlugin({ beautify: false, //prod output: { comments: false }, //prod mangle: { screw_ie8: true }, //prod compress: { screw_ie8: true, warnings: false, conditionals: true, unused: true, comparisons: true, sequences: true, dead_code: true, evaluate: true, if_return: true, join_vars: true, negate_iife: false // we need this for lazy v8 }, }) : null, DEV_SERVER ? new ElectronConnectWebpackPlugin({ path: helpers.root('dev'), stopOnClose: true, logLevel: 0 }) : null, ].filter(plugin => plugin !== null), target: "electron" }; }
{ from: './src/img/*', to: 'img/[name].[ext]' }, { from: './node_modules/fixed-data-table-2/dist/fixed-data-table-base.css', to: 'css/fixed-data-table-base.css', }, { from: './libs/libgme.dylib', to: 'libgme.dylib' }, { from: './libs/libaosdk.dylib', to: 'libaosdk.dylib' }, { from: './libs/mgba_libretro.dylib', to: 'mgba_libretro.dylib' }, { from: './libs/libsoxr.dylib', to: 'libsoxr.dylib' }, ]), ], node: { __dirname: false, }, externals: [ nodeExternals(), ], module: { rules: [ { test: /\.js$/, exclude: /node_modules/, loader: 'babel-loader', }, ], }, resolve: { alias: { moseamp: path.resolve(__dirname, 'src'), }, },
// Configuration for client-side bundle suitable for running in browsers var clientBundleConfig = merge(sharedConfig, { entry: { 'main-client': './ClientApp/boot-client.ts' }, output: { path: path.join(__dirname, './wwwroot/dist') }, devtool: isDevBuild ? 'inline-source-map' : null, plugins: [ new webpack.DllReferencePlugin({ context: __dirname, manifest: require('./wwwroot/dist/vendor-manifest.json') }) ].concat(isDevBuild ? [] : [ // Plugins that apply in production builds only new webpack.optimize.OccurenceOrderPlugin(), new webpack.optimize.UglifyJsPlugin() ]) }); // Configuration for server-side (prerendering) bundle suitable for running in Node var serverBundleConfig = merge(sharedConfig, { entry: { 'main-server': './ClientApp/boot-server.ts' }, output: { libraryTarget: 'commonjs', path: path.join(__dirname, './ClientApp/dist') }, target: 'node', devtool: 'inline-source-map', externals: [nodeExternals({ whitelist: [allFilenamesExceptJavaScript] })] // Don't bundle .js files from node_modules }); module.exports = [clientBundleConfig, serverBundleConfig];
module.exports = { entry: './src/index.ts', target: 'node', output: { path: path.resolve(__dirname, 'lib'), filename: 'app.js', libraryExport: '' }, module: { loaders: [ { test: /\.tsx?$/, loaders: ['babel-loader', 'ts-loader'], exclude: /node_modules/ }, { test: /\.js/, loader: 'babel-loader', exclude: /node_modules/ } ] }, stats: { colors: true }, resolve: { extensions: ['.ts', '.js'] }, externals: [nodeExternals()] };
export default function webpackFactory({ production = false, client = false }) { return { stats: { children: false, }, entry: client ? { bundle: [ !production && 'webpack-dev-server/client?/', !production && 'webpack/hot/only-dev-server', 'babel-polyfill', path.resolve(__dirname, '..', '..', 'src', 'client', 'index.js'), ].filter(identity), } : { server: [ 'babel-polyfill', path.resolve(__dirname, '..', '..', 'src', 'server', 'index.js'), ], }, output: { filename: client ? '[name]-[hash:6].js' : '[name].js', path: path.resolve(__dirname, '..', '..', 'dist'), publicPath: '/dist/', }, target: client ? 'web' : 'node', externals: [!client && nodeExternals({ whitelist: [ 'font-awesome/css/font-awesome.min.css', 'gemini-scrollbar/gemini-scrollbar.css', ], })].filter(identity), devtool: !production || !client ? 'cheap-module-inline-source-map' : 'hidden-source-map', debug: true, module: { loaders: [ { test: /\.js$/, exclude: /node_modules/, loaders: [!production && 'react-hot', 'babel'].filter(identity), }, { test: /\.json$/, loader: 'json', }, { test: /\.styl$/, loader: stylusLoader({ production, client }), }, { test: /\.css$/, loader: cssLoader({ production, client }), }, { test: /\.(?:jpe?g|png|svg|woff2?|eot|ttf)(?:\?.*$|$)/, loader: 'url?limit=5120&name=[name]-[hash:6].[ext]', }, ], }, postcss: [autoprefixer({ browsers: ['last 2 versions'] })], plugins: [ new DefinePlugin({ __CLIENT__: client, __DEVELOPMENT__: !production, __SERVER__: !client, // 'process.env.NODE_ENV': JSON.stringify('production'), }), new ProvidePlugin({ fetch: 'isomorphic-fetch', }), new NoErrorsPlugin(), !production && new HotModuleReplacementPlugin(), client && production && new ExtractTextPlugin('[name]-[contenthash:6].css', { allChunks: true, }), !client && !production && new BannerPlugin('require("source-map-support").install();', { raw: true, entryOnly: false, }), production && new optimize.DedupePlugin(), production && new optimize.OccurenceOrderPlugin(), production && new optimize.UglifyJsPlugin({ compressor: { warnings: false, }, }), client && new WriteManifestPlugin({ client }), ].filter(identity), resolve: { alias: { root: path.resolve(__dirname, '..', '..', 'src'), }, extensions: ['', '.json', '.js', '.styl'], modulesDirectories: [ 'src', 'node_modules', ], }, }; }
`presets[]=babel-preset-stage-0&` + `plugins[]=babel-plugin-transform-decorators-legacy` + `!ts?silent=true` } ] }, // in order to ignore built-in modules like path, fs, etc. target: 'node', node: { __dirname: false, __filename: false }, externals: [ // require json files with nodes built-in require logic function(context, request, callback) { if (/\.json$/.test(request)) { callback(null, `require('${request}')`); } else { callback(); } }, // in order to ignore all modules in node_modules folder WebpackNodeExternals() ], devtool: 'cheap-module-inline-source-map', resolve: { // Add `.ts` and `.tsx` as a resolvable extension. extensions: [ '', '.ts', '.tsx', '.js' ] } };
function config({ target = 'client', env = process.env.NODE_ENV }) { const web = target === 'client'; const dev = env === 'development'; return { target: web ? 'web' : 'node', devtool: dev ? (web ? 'eval-source-map' : 'inline-source-map') : null, debug: dev, entry: { [target] : [ ...(dev ? (web ? ['webpack-hot-middleware/client', 'react-hot-loader/patch'] : ['source-map-support/register', 'webpack/hot/poll?1000']) : []), `./src/${target}`, ], [`${web ? '../' : ''}tests/${target}`]: `./src/${target}/tests`, }, output: { libraryTarget: 'umd', path: path.resolve(__dirname, 'build', web ? 'public' : ''), publicPath: '/public/', chunkFilename: 'chunks/[id].js', filename: '[name].js', pathInfo: dev, }, url: { dataUrlLimit: 1024, }, module: { loaders: [ { test: /\.json$/i, loader: 'json', }, { test: /\.jsx?$/i, exclude: /node_modules/, loader: 'babel', query: Object.assign({}, pkg.babel, { babelrc: false, presets: web ? ([ ...pkg.babel.presets.filter((preset) => preset !== 'es2015-auto'), ...(dev ? ['es2015'] : ['es2015-webpack', 'es2015-webpack-loose']), ]) : pkg.babel.presets, plugins: [...pkg.babel.plugins, ...(dev ? ['react-hot-loader/babel'] : [])], }), }, { test: /\.(gif|png|jpe?g|svg)$/i, loaders: [ `${web ? '' : 'fake-'}url?name=images/[hash].[ext]`, 'image-webpack?{progressive:true, optimizationLevel: 7, interlaced: false, pngquant:{quality: "65-90", speed: 4}}', ], }, { test: /\.(woff2?|[ot]tf|eot)$/i, loaders: [ `${web ? '' : 'fake-'}url?name=fonts/[hash].[ext]`, ], }, { test: /\.css$/i, exclude: /node_modules/, loaders: ExtractTextWebpackPlugin.extract( web ? `style${dev ? '?sourceMap' : ''}` : 'fake-style', `css?${dev ? 'sourceMap&' : 'minimize&'}modules&importLoaders=1&localIdentName=${dev ? '[path]___[name]__[local]___' : ''}[hash:base64:5]!postcss`, ), }, { test: /.*\/node_modules\/.*\.css$/i, loaders: ExtractTextWebpackPlugin.extract( web ? `style${dev ? '?sourceMap' : ''}` : 'fake-style', `css?${dev ? 'sourceMap' : 'minimize'}`, ), }, ], }, postcss: () => [postCssCssNext], plugins: [ new webpack.DefinePlugin({ 'process.env.NODE_ENV': JSON.stringify(env), }), new ExtractTextWebpackPlugin('client.css', { allChunks: true, disable: dev || !web, }), new webpack.optimize.OccurrenceOrderPlugin(), ...(dev ? [ new webpack.HotModuleReplacementPlugin(), new webpack.NoErrorsPlugin(), ] : [ new webpack.optimize.DedupePlugin(), ...(web ? [ new webpack.optimize.UglifyJsPlugin({ output: { comments: false, }, compress: { warnings: false, }, }) ] : [ new StaticSiteGeneratorWebpackPlugin('server', ['index.html']), ]), ] ), ], externals: web ? null : [webpackNodeExternals({ whitelist: ['webpack/hot/poll?1000'], })], node: web ? { fs: 'empty', } : { __filename: false, __dirname: false, }, resolve: { extensions: ['', '.js', '.json', '.jsx'], }, }; }
rules: [ USE_ESLINT_LOADER && { test: /\.jsx?$/, loader: 'eslint-loader', enforce: 'pre', exclude: /node_modules/ }, { test: /\.jsx?$/, loader: 'babel-loader', options: babelConfig, exclude: /node_modules/ } ].filter(Boolean) }, externals: [nodeExternals()], // ignore all modules in node_modules folder resolve: { extensions: ['.js', '.jsx'] }, resolveLoader: { modules: [ path.resolve(__dirname, 'node_modules') ] }, node: { console: true, global: true, process: true, Buffer: true, __filename: true, // Use relative path __dirname: true, // Use relative path
const path = require('path'); const nodeExternals = require('webpack-node-externals'); const CopyWebpackPlugin = require('copy-webpack-plugin'); module.exports = { entry: './projects/schematics/src/ng-add/index.js', output: { path: path.resolve(__dirname, 'dist/made-with-love/schematics/ng-add'), filename: 'index.js', libraryTarget: 'commonjs2' }, mode: 'production', target: 'node', externals: [ nodeExternals({ whitelist: ['schematics-utilities'] }) ], plugins: [ new CopyWebpackPlugin( [ { from: 'projects/schematics/src/collection.json', to: '../collection.json', toType: 'file' }, { from: 'README.md', to: '../../README.md', toType: 'file' }
import nodeExternals from 'webpack-node-externals' import { jsConfig } from './webpack.config.base' const config = jsConfig() const coreConfig = jsConfig() coreConfig.externals = [nodeExternals()] coreConfig.output.filename = '[name].core.js' export default [config, coreConfig]
modify: (config, { target, dev }, webpack) => { const BASE_CSS_LOADER = { loader: 'css-loader', options: { importLoaders: 2, sourceMap: true, localIdentName: '[name]__[local]___[hash:base64:5]', }, }; const POST_CSS_LOADER = { loader: require.resolve('postcss-loader'), options: { sourceMap: true, // Necessary for external CSS imports to work // https://github.com/facebookincubator/create-react-app/issues/2677 ident: 'postcss', plugins: () => [ require('postcss-flexbugs-fixes'), autoprefixer({ browsers: [ '>1%', 'last 4 versions', 'Firefox ESR', 'not ie < 9', // React doesn't support IE8 anyway ], flexbox: 'no-2009', }), ], }, }; const LESSLOADER = { test: /\.less$/, include: [ path.resolve('./theme'), /node_modules\/@plone\/volto\/theme/, /@plone\/volto\/theme/, /node_modules\/semantic-ui-less/, ], use: dev ? [ { loader: 'style-loader', }, BASE_CSS_LOADER, POST_CSS_LOADER, { loader: 'less-loader', options: { outputStyle: 'expanded', sourceMap: true, }, }, ] : [ MiniCssExtractPlugin.loader, { loader: 'css-loader', options: { importLoaders: 2, sourceMap: true, modules: false, localIdentName: '[name]__[local]___[hash:base64:5]', }, }, POST_CSS_LOADER, { loader: 'less-loader', options: { outputStyle: 'expanded', sourceMap: true, }, }, ], }; const SVGLOADER = { test: /icons\/.*\.svg$/, use: [ { loader: 'svg-loader', }, { loader: 'svgo-loader', options: { plugins: [ { removeTitle: true }, { convertPathData: false }, { removeUselessStrokeAndFill: true }, { removeViewBox: false }, ], }, }, ], }; if (target === 'web') { config.plugins.unshift( new webpack.DefinePlugin({ __CLIENT__: true, __SERVER__: false, }), ); } if (target === 'node') { config.plugins.unshift( new webpack.DefinePlugin({ __CLIENT__: false, __SERVER__: true, }), ); } config.module.rules.push(LESSLOADER); config.module.rules.push(SVGLOADER); // Don't load config|variables|overrides) files with file-loader // Don't load SVGs from ./src/icons with file-loader const fileLoader = config.module.rules.find(fileLoaderFinder); fileLoader.exclude = [ /\.(config|variables|overrides)$/, /icons\/.*\.svg$/, ...fileLoader.exclude, ]; // Disabling the ESlint pre loader config.module.rules.splice(0, 1); let voltoPath = `${projectRootPath}`; if (packageJson.name !== '@plone/volto') { voltoPath = `${projectRootPath}/node_modules/@plone/volto`; } const jsconfigPaths = {}; if (fs.existsSync(`${projectRootPath}/jsconfig.json`)) { const jsConfig = require(`${projectRootPath}/jsconfig`).compilerOptions; const pathsConfig = jsConfig.paths; Object.keys(pathsConfig).forEach(packageName => { const packagePath = `${projectRootPath}/${jsConfig.baseUrl}/${ pathsConfig[packageName][0] }`; jsconfigPaths[packageName] = packagePath; if (packageName === '@plone/volto') { voltoPath = packagePath; } }); } const customizations = {}; let { customizationPaths } = packageJson; if (!customizationPaths) { customizationPaths = ['src/customizations/']; } customizationPaths.forEach(customizationPath => { map( glob( `${customizationPath}**/*.*(svg|png|jpg|jpeg|gif|ico|less|js|jsx)`, ), filename => { const targetPath = filename.replace( customizationPath, `${voltoPath}/src/`, ); if (fs.existsSync(targetPath)) { customizations[ filename .replace(customizationPath, '@plone/volto/') .replace(/\.(js|jsx)$/, '') ] = path.resolve(filename); } else { console.log( `The file ${filename} doesn't exist in the volto package (${targetPath}), unable to customize.`, ); } }, ); }); config.resolve.alias = { ...customizations, ...config.resolve.alias, '../../theme.config$': `${projectRootPath}/theme/theme.config`, ...jsconfigPaths, '@plone/volto': `${voltoPath}/src`, // to be able to reference path uncustomized by webpack '@plone/volto-original': `${voltoPath}/src`, // be able to reference current package from customized package '@package': `${projectRootPath}/src`, }; config.performance = { maxAssetSize: 10000000, maxEntrypointSize: 10000000, }; const babelRuleIndex = config.module.rules.findIndex( rule => rule.use && rule.use[0].loader && rule.use[0].loader.includes('babel-loader'), ); const { include } = config.module.rules[babelRuleIndex]; if (packageJson.name !== '@plone/volto') { include.push(fs.realpathSync(`${voltoPath}/src`)); } config.module.rules[babelRuleIndex] = Object.assign( config.module.rules[babelRuleIndex], { include, }, ); config.externals = target === 'node' ? [ nodeExternals({ whitelist: [ dev ? 'webpack/hot/poll?300' : null, /\.(eot|woff|woff2|ttf|otf)$/, /\.(svg|png|jpg|jpeg|gif|ico)$/, /\.(mp4|mp3|ogg|swf|webp)$/, /\.(css|scss|sass|sss|less)$/, /^@plone\/volto/, ].filter(Boolean), }), ] : []; return config; },
const path = require('path'); const nodeExternals = require('webpack-node-externals'); const CleanWebpackPlugin = require('clean-webpack-plugin'); module.exports = { context: path.resolve(__dirname), entry: './src/index.js', target: 'node', externals: [nodeExternals({ whitelist: [/^bootstrap/, /^@fortawesome/] })], module: { rules: [ { test: /\.(js|jsx)$/, exclude: /(node_modules|bower_components)/, use: { loader: 'babel-loader' } }, { test: /\.(css|png|svg|jpg|jpeg|gif|woff|woff2|eot|ttf|otf)$/, use: { loader: 'ignore-loader' } }, ] }, plugins: [ new CleanWebpackPlugin(['dist'], { root: path.resolve(__dirname)
// 配置编译的入口文件 entry: './src/entry-server.js', // 设置输出文件名,并设置模块导出为commonjs2类型 output: { filename: 'server-bundle.js', libraryTarget: 'commonjs2' }, // 在alias设置好服务端数据请求API为create-api-server.js模块 resolve: { alias: { 'create-api': './create-api-server.js' } }, // https://webpack.js.org/configuration/externals/#externals // https://github.com/liady/webpack-node-externals // 设置不打包排除规则 externals: nodeExternals({ // do not externalize CSS files in case we need to import it from a dep whitelist: /\.css$/ }), plugins: [ // 设置环境变量 new webpack.DefinePlugin({ 'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || 'development'), 'process.env.VUE_ENV': '"server"' }), //设置VueSSRServerPlugin插件 new VueSSRServerPlugin() ] })
const merge = require('webpack-merge') const nodeExternals = require('webpack-node-externals') const baseConfig = require('./webpack.base.conf.js') const VueSSRServerPlugin = require('vue-server-renderer/server-plugin') const path = require('path') const webpack = require('webpack') module.exports = merge(baseConfig, { entry: path.resolve(__dirname, '../src/entry-server.js'), target: 'node', devtool: 'source-map', output: { libraryTarget: 'commonjs2' }, externals: nodeExternals({ whitelist: /\.css$/ }), plugins: [ new webpack.DefinePlugin({ 'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || 'development'), 'process.env.VUE_ENV': '"server"' }), new VueSSRServerPlugin() ] })
const finalConfig = Object.assign({}, config, { entry: { cli: './src/cli.ts' }, target: 'node', node: { __filename: false, __dirname: false, console: false, global: false, process: false, Buffer: false, }, externals: [ nodeExternals({ whitelist }), nodeExternals({ whitelist, modulesDir: path.resolve(__dirname, '../../node_modules') }) ], }) finalConfig.output.libraryTarget = 'umd' finalConfig.output.library = { root: 'TygenHtml', amd: '@tygen/html', commonjs: '@tygen/html' }
const webpack = require('webpack'); const path = require('path'); const nodeExternals = require('webpack-node-externals'); module.exports = { entry: ['webpack/hot/poll?100', './src/main.ts'], watch: true, target: 'node', externals: [ nodeExternals({ whitelist: ['webpack/hot/poll?100'], }), ], module: { rules: [ { test: /\.tsx?$/, use: 'ts-loader', exclude: /node_modules/, }, ], }, mode: 'development', resolve: { extensions: ['.tsx', '.ts', '.js'], }, plugins: [new webpack.HotModuleReplacementPlugin()], output: { path: path.join(__dirname, 'dist'), filename: 'server.js', },
stats: 'errors-only', devtool: 'source-map', entry: { lib: path.join(__dirname, 'src', 'index.ts'), }, output: { path: path.join(__dirname, 'lib'), filename: '[name].js', library: '@spinnaker/kubernetes', libraryTarget: 'umd', umdNamedDefine: true, }, externals: [ '@spinnaker/core', 'exports-loader?"n3-line-chart"!n3-charts/build/LineChart.js', nodeExternals({ modulesDir: '../../../../node_modules' }), ], resolve: { extensions: ['.json', '.js', '.jsx', '.ts', '.tsx', '.css', '.less', '.html'], modules: [ NODE_MODULE_PATH, path.resolve('.'), ], alias: { '@spinnaker/kubernetes': path.join(__dirname, 'src'), 'coreImports': path.resolve(basePath, 'app', 'scripts', 'modules', 'core', 'src', 'presentation', 'less', 'imports', 'commonImports.less'), 'kubernetes': path.join(__dirname, 'src') } }, watch: process.env.WATCH === 'true', module: {
const HappyPack = require('happypack') const nodeExternals = require('webpack-node-externals') const webpack = require('webpack') const dir = require(`${global.baseDir}globalDirs`) const config = require(`${dir.configs}configSettings`) const paths = require(`${dir.includes}paths`) const webpackDefaultConfig = require(`${dir.configs}webpack.config.default`) const threadPool = HappyPack.ThreadPool({ size: 2 }) const webpackConfig = { entry: `./${paths.root.src}server`, externals: [ nodeExternals({ whitelist: [/.*\.css/] }) ], output: { filename: 'backend.js', libraryTarget: 'commonjs2', path: `${global.baseDir}/web/`, pathinfo: false, publicPath: '/', }, plugins: [ new webpack.LoaderOptionsPlugin({ minimize: true, }), new webpack.ProgressPlugin((percentage, msg) => { console.info(Math.round(percentage * 100), `prod-server ${msg}`)
options: { ...rule.options, name: `public/assets/${rule.options.name}`, publicPath: url => url.replace(/^public/, ''), }, }; } return rule; }), }, externals: [ './assets.json', nodeExternals({ whitelist: [reStyle, reImage], }), ], plugins: [ // Define free variables // https://webpack.js.org/plugins/define-plugin/ new webpack.DefinePlugin({ 'process.env.NODE_ENV': isDebug ? '"development"' : '"production"', 'process.env.BROWSER': false, __DEV__: isDebug, }), // Adds a banner to the top of each generated chunk // https://webpack.js.org/plugins/banner-plugin/ new webpack.BannerPlugin({
path: path.resolve(__dirname, "dist"), filename: "[name].bundle.js" }, node: { __dirname: true, fs: "empty", net: "empty", child_process: "empty" }, resolve: { // alias: { // "node-opcua": "./node-opcua" // } }, externals: [nodeExternals({ //xx whitelist: [/opcua/] }),"node-opcua"], // "spawn-sync", "camelcase", "string-width", "read-pkg-up", "os-locale", "memcpy", "yargs", "ursa", "usage", "require-main-filename"], // module: { // rules: [ // { // test: /\.js$/, // //xx exclude: [/node_modules/], // loader: "babel-loader", // query: { // presets: ["es2015"], // }, // } // ]
new webpack.optimize.DedupePlugin(), new webpack.optimize.UglifyJsPlugin(), ], output: { path: path.join(__dirname, 'lib'), publicPath: 'lib/', filename: '[name].js', chunkFilename: '[id].js', sourceMapFilename: '[name].js.map', library: 'squalus', }, resolve: { modulesDirectories: ['node_modules'], extensions: ['', '.js'], }, module: { loaders: [ { test: /\.js$/, loader: 'babel', exclude: /node_modules/, }, { test: /\.css$/, loader: 'style!css', }, ], }, externals: [externals()], };
module.exports = merge(baseConfig, { // 将 entry 指向应用程序的 server entry 文件 entry: path.resolve('./src/entry-server.js'), // 这允许 webpack 以 Node 适用方式(Node-appropriate fashion)处理动态导入(dynamic import), // 并且还会在编译 Vue 组件时, // 告知 `vue-loader` 输送面向服务器代码(server-oriented code)。 target: 'node', // 对 bundle renderer 提供 source map 支持 devtool: 'source-map', // 此处告知 server bundle 使用 Node 风格导出模块(Node-style exports) output: { libraryTarget: 'commonjs2' }, // https://webpack.js.org/configuration/externals/#function // https://github.com/liady/webpack-node-externals // 外置化应用程序依赖模块。可以使服务器构建速度更快, // 并生成较小的 bundle 文件。 externals: nodeExternals({ // 不要外置化 webpack 需要处理的依赖模块。 // 你可以在这里添加更多的文件类型。例如,未处理 *.vue 原始文件, // 你还应该将修改 `global`(例如 polyfill)的依赖模块列入白名单 whitelist: /\.css$/ }), // 这是将服务器的整个输出 // 构建为单个 JSON 文件的插件。 // 默认文件名为 `vue-ssr-server-bundle.json` plugins: [ new VueSSRServerPlugin() ] })
const webpack = require('webpack') const path = require('path') const nodeExternals = require('webpack-node-externals') const StartServerPlugin = require('start-server-webpack-plugin') module.exports = { entry: [ 'webpack/hot/poll?1000', './server/index' ], watch: true, target: 'node', externals: [nodeExternals({ whitelist: ['webpack/hot/poll?1000'] })], module: { rules: [{ test: /\.js?$/, use: 'babel-loader', exclude: /node_modules/ }] }, plugins: [ new StartServerPlugin('server.js'), new webpack.NamedModulesPlugin(), new webpack.HotModuleReplacementPlugin(), new webpack.NoEmitOnErrorsPlugin(), new webpack.DefinePlugin({ 'process.env': { 'BUILD_TARGET': JSON.stringify('server') }
const path = require('path'); const merge = require('webpack-merge'); const baseConfig = require('./webpack.base.js'); const webpackNodeExternals = require('webpack-node-externals'); const config = { target: 'node', entry: './src/index.js', output: { filename: 'bundle.js', path: path.resolve(__dirname, 'build') }, externals: [webpackNodeExternals()] }; module.exports = merge(baseConfig, config);
var webpack = require('webpack') const path = require('path') var nodeExternals = require('webpack-node-externals') var pkg = require('./package.json') var nodeConfig = { devtool: 'source-map', entry: ['./src/index.js'], output: { path: path.resolve(__dirname, './bin'), filename: 'node.bundle.js', libraryTarget: 'commonjs2' }, externals: [nodeExternals(), 'botpress'], target: 'node', resolve: { extensions: ['.js'] }, module: { rules: [ { test: /\.js$/, use: { loader: 'babel-loader', options: { presets: ['latest', 'stage-0'], plugins: ['transform-object-rest-spread', 'transform-async-to-generator'] } }, exclude: /node_modules/ }
function webpackConfigFactory({ target, mode }) { if (!target || !~['client', 'server'].findIndex(valid => target === valid)) { throw new Error( 'You must provide a "target" (client|server) to the webpackConfigFactory.' ); } if (!mode || !~['development', 'production'].findIndex(valid => mode === valid)) { throw new Error( 'You must provide a "mode" (development|production) to the webpackConfigFactory.' ); } console.log(`==> ℹ️ Creating webpack "${target}" config in "${mode}" mode`); const isDev = mode === 'development'; const isProd = mode === 'production'; const isClient = target === 'client'; const isServer = target === 'server'; const ifDev = ifElse(isDev); const ifProd = ifElse(isProd); const ifClient = ifElse(isClient); const ifServer = ifElse(isServer); const ifDevClient = ifElse(isDev && isClient); const ifDevServer = ifElse(isDev && isServer); const ifProdClient = ifElse(isProd && isClient); return { // We need to state that we are targetting "node" for our server bundle. target: ifServer('node', 'web'), // We have to set this to be able to use these items when executing a // server bundle. Otherwise strangeness happens, like __dirname resolving // to '/'. There is no effect on our client bundle. node: { __dirname: true, __filename: true, }, // cache: !(isDev && isServer), // Anything listed in externals will not be included in our bundle. externals: removeEmpty([ // We don't want our node_modules to be bundled with our server package, // prefering them to be resolved via native node module system. Therefore // we use the `webpack-node-externals` library to help us generate an // externals config that will ignore all node_modules. ifServer(nodeExternals()), ]), devtool: ifElse(isServer || isDev)( // We want to be able to get nice stack traces when running our server // bundle. To fully support this we'll also need to configure the // `node-source-map-support` module to execute at the start of the server // bundle. This module will allow the node to make use of the // source maps. // We also want to be able to link to the source in chrome dev tools // whilst we are in development mode. :) 'source-map', // When in production client mode we don't want any source maps to // decrease our payload sizes. // This form has almost no cost. 'hidden-source-map' ), // Define our entry chunks for our bundle. entry: merge( { main: removeEmpty([ ifDevClient('react-hot-loader/patch'), ifDevClient(`webpack-hot-middleware/client?reload=true&path=http://localhost:${process.env.CLIENT_DEVSERVER_PORT}/__webpack_hmr`), path.resolve(__dirname, `./src/${target}/index.js`), ]), }, ifClient({ // We create a seperate chunk containing our vendor modules. This can // avoid unnecessary downloads by users as well as speed up development // rebuild times by not having to rebundle everything with every change. vendor: removeEmpty([ 'react', 'react-dom', ]), }) ), output: { // The dir in which our bundle should be output. path: path.resolve(__dirname, `./build/${target}`), // The filename format for our bundle's entries. filename: ifProdClient( // We include a hash for client caching purposes. Including a unique // has for every build will ensure browsers always fetch our newest // bundle. '[name]-[hash].js', // We want a determinable file name when running our server bundles, // as we need to be able to target our server start file from our // npm scripts. We don't care about caching on the server anyway. // We also want our client development builds to have a determinable // name for our hot reloading client bundle server. '[name].js' ), chunkFilename: '[name]-[chunkhash].js', // This is the web path under which our webpack bundled output should // be considered as being served from. Useful in the client bundle context // only. publicPath: ifDevClient( // As we run a seperate server for our client and server bundles we // need to use an absolute http path for our assets public path. `http://localhost:${process.env.CLIENT_DEVSERVER_PORT}/assets/`, // Otherwise we expect our bundled output to be served from this path. '/assets/' ), // When in server mode we will output our bundle as a commonjs2 module. libraryTarget: ifServer('commonjs2', 'var'), }, resolve: { // These extensions are tried when resolving a file. extensions: ['.js', '.json'], }, plugins: removeEmpty([ // Each key passed into DefinePlugin is an identifier. // The values for each key will be inlined into the code replacing any // instances of the keys that are found. // If the value is a string it will be used as a code fragment. // If the value isn’t a string, it will be stringified (including functions). // If the value is an object all keys are removeEmpty the same way. // If you prefix typeof to the key, it’s only removeEmpty for typeof calls. new webpack.DefinePlugin({ 'process.env': { // NOTE: The NODE_ENV key is especially important for production // builds as React relies on process.env.NODE_ENV for optimizations. NODE_ENV: JSON.stringify(mode), // All the below items match the config items in our .env file. Go // to the .env_example for a description of each key. SERVER_PORT: JSON.stringify(process.env.SERVER_PORT), CLIENT_DEVSERVER_PORT: JSON.stringify(process.env.CLIENT_DEVSERVER_PORT), DISABLE_SSR: process.env.DISABLE_SSR, WEBSITE_TITLE: JSON.stringify(process.env.WEBSITE_TITLE), WEBSITE_DESCRIPTION: JSON.stringify(process.env.WEBSITE_DESCRIPTION), }, }), // Generates a JSON file containing a map of all the output files for // our webpack bundle. A necessisty for our server rendering process // as we need to interogate these files in order to know what JS/CSS // we need to inject into our HTML. new AssetsPlugin({ filename: 'assets.json', path: path.resolve(__dirname, `./build/${target}`), }), // Ensures all our vendor bundle is a single file output and that any // shared code between our main and vendor bundles are put into the vendor // bundle. ifClient( new webpack.optimize.CommonsChunkPlugin({ name: 'vendor', minChunks: Infinity, }) ), // We don't want webpack errors to occur during development as it will // kill our dev servers. ifDev(new webpack.NoErrorsPlugin()), // We need this plugin to enable hot module reloading for our dev server. ifDevClient(new webpack.HotModuleReplacementPlugin()), // Ensure only 1 file is output for the server bundles. This makes it // much easer for us to clear the module cache when reloading the server. ifDevServer(new webpack.optimize.LimitChunkCountPlugin({ maxChunks: 1 })), // Adds options to all of our loaders. ifProdClient( new webpack.LoaderOptionsPlugin({ // Indicates to our loaders that they should minify their output // if they have the capability to do so. minimize: true, // Indicates to our loaders that they should enter into debug mode // should they support it. debug: false, }) ), ifProdClient( // JS Minification. new webpack.optimize.UglifyJsPlugin({ compress: { screw_ie8: true, warnings: false, }, }) ), ifProd( // This is actually only useful when our deps are installed via npm2. // In npm2 its possible to get duplicates of dependencies bundled // given the nested module structure. npm3 is flat, so this doesn't // occur. new webpack.optimize.DedupePlugin() ), ]), module: { loaders: [ // Javascript { test: /\.js$/, loader: 'babel-loader', exclude: [/node_modules/, path.resolve(__dirname, './build')], query: merge( { env: { development: { plugins: ['react-hot-loader/babel'], }, }, }, ifServer({ // We are running a node 6 server which has support for almost // all of the ES2015 syntax, therefore we only transpile JSX. presets: ['react'], }), ifClient({ // For our clients code we will need to transpile our JS into // ES5 code for wider browser/device compatability. presets: [ // JSX 'react', // Webpack 2 includes support for es2015 imports, therefore we used this // modified preset. 'es2015-webpack', ], }) ), }, // JSON { test: /\.json$/, loader: 'json-loader', }, ], }, }; }
const VueLoaderPlugin = require('vue-loader/lib/plugin') const NodeExternals = require('webpack-node-externals') // ^ This makes it so that we can exclude all of node_modules. const webpack = require('webpack') module.exports = { // target: 'node', // in order to ignore built-in modules like path, fs, etc. mode: 'development', // mode: 'production', // ^ Do not change this to production, always leave it at development. 'Production mode' actually slows the app down! Webpack apparently is designed to optimise for file size / it being single block over the actual app speed. This was surprising to see... In our context, we have no need for saving a few Kbs on JS sizes, nor we incur any penalty for readind JS files from disk, so we gain nothing from being in production, and lose some speed. target: 'electron-renderer', node: { __dirname: false, __filename: false, }, externals: [NodeExternals()], // in order to ignore all modules in node_modules folder entry: './src/app/renderermain.ts', output: { path: path.resolve(__dirname, 'dist'), filename: 'bundle.js', }, resolve: { // Add `.ts` as a resolvable extension. extensions: ['.ts', '.js', '.vue'], }, module: { rules: [ { test: /\.ts$/, // exclude: /node_modules|vue\/src/, loader: 'ts-loader',
const nodeExternals = require('webpack-node-externals'); const jsDir = path.resolve('./src/server'); const entryOut = path.resolve('./dist/server'); module.exports = { entry: ['babel-regenerator-runtime', path.resolve(jsDir, 'index.js')], target: 'node', node: { __dirname: true }, output: { path: entryOut, filename: 'index.js' }, externals: nodeExternals(), module: { preLoaders: [ { test: /\.js$/, loader: 'eslint', exclude: /node_modules/ } ], loaders: [ { test: /\.js$/, loader: 'babel', exclude: /(node_modules)/ }, { test: /\.json$/, loader: 'json', exclude: /(node_modules)/ } ] }, plugins: [ new webpack.NoErrorsPlugin() ], resolve: { modulesDirectories: ['node_modules', jsDir] },
config.devtool = 'source-map'; config.plugins.push( new webpack.optimize.UglifyJsPlugin({ 'screw-ie8': true, mangle: { toplevel: false }, compress: { warnings: false }, comments: false }) ); config.plugins.push( new webpack.optimize.AggressiveMergingPlugin() ); config.plugins.push( new webpack.optimize.OccurrenceOrderPlugin(true) ); config.plugins.push( new webpack.optimize.DedupePlugin() ); } // Test mode configuration if (TEST) { config.externals = [nodeExternals()]; } module.exports = config;
options: { test: /\.ts$/, ts: { compiler: 'typescript', configFile: 'tsconfig.json' }, tslint: { emitErrors: true, failOnHint: true } } }) ], devtool: 'source-map', module: { rules: [{ test: /\.ts$/, loaders: 'ts-loader' }, { test: /\.graphql?/, use: 'raw-loader' },] }, externals: [ nodeExternals({ modulesDir: "../../node_modules" }), nodeExternals() ] }; module.exports = webpack_opts;